How to open a new tab using Selenium WebDriver in Java?

How can I open a new tab in the existing Firefox browser using Selenium WebDriver (a.k.a. Selenium 2) in Java?

Answer

The code below will open the link in a new tab.

String selectLinkOpeninNewTab = Keys.chord(Keys.CONTROL,Keys.RETURN);
driver.findElement(By.linkText("urlLink")).sendKeys(selectLinkOpeninNewTab);

The code below will open an empty new tab.

String selectLinkOpeninNewTab = Keys.chord(Keys.CONTROL,"t");
driver.findElement(By.linkText("urlLink")).sendKeys(selectLinkOpeninNewTab);

Leave a Reply

Your email address will not be published. Required fields are marked *