How to open a new tab in the existing Firefox browser using Selenium WebDriver (a.k.a. Selenium 2)?
If you want to open the new tab you can use this
((JavascriptExecutor) getDriver()).executeScript("window.open()");
If you want to open the link from the new tab you can use this
with JavascriptExecutor:
public void openFromNewTab(WebElement element){
((JavascriptExecutor)getDriver()).executeScript("window.open('"+element.getAttribute("href")+"','_blank');");
}
with Actions:
WebElement element = driver.findElement(By.xpath("your_xpath"));
Actions actions = new Actions(driver);
actions.keyDown(Keys.LEFT_CONTROL)
.click(element)
.keyUp(Keys.LEFT_CONTROL)
.build()
.perform();