javaseleniumselenium-webdriverfirefoxbrowser-tab

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?


Solution

  • 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);