Opening a new tab in the same window session of the browser through Selenium WebDriver?

12,458

Solution 1

Opening a new tab in the same browser window is possible, see solutions for Firefox:

The problem is - once you've opened a tab, there is no built-in easy way to switch between tabs. Selenium simply doesn't provide an API for that.

Instead of a tab, open a new browser window.

Solution 2

Yes you can do that , See below my sample code for that :

   //OPEN SPECIFIC URL IN BROWSER
    driver.get("http://www.toolsqa.com/automation-practice-form/");

   //MAXIMIZE BROWSER WINDWO
    driver.manage().window().maximize();


   //OPEN LINKED URL IN NEW TAB IN SAME BROWSER 
   String link1 = Keys.chord(Keys.CONTROL,Keys.ENTER); 
   driver.findElement(By.linkText("Partial Link Test")).sendKeys(link1);

Above code will open link1 in new tab. you can run above code to see effect. Above is public link includes testing form.

But as @alecxe told that there is no way to switch between tabs. So better you open new browser window.

Share:
12,458
Bharadwaj Pendyala
Author by

Bharadwaj Pendyala

Null

Updated on June 05, 2022

Comments

  • Bharadwaj Pendyala
    Bharadwaj Pendyala almost 2 years

    How to open a new tab in the same window session of the browser through Selenium WebDriver command?