How to open a new tab in the existing Firefox browser using Selenium WebDriver (a.k.a. Selenium 2)?
I had trouble opening a new tab in chrome for a while.
Even driver.findElement(By.cssSelector("body")).sendKeys(Keys.CONTROL + "t");
Didn't work for me.
I found out that it's not enough that selenium has focus on driver, Windows also has to have the window in the front.
My solution was to invoke an alert on chrome that would bring the window to front and then execute the command. sample code:
((JavascriptExecutor)driver).executeScript("alert('Test')");
driver.switchTo().alert().accept();
driver.findElement(By.cssSelector("body")).sendKeys(Keys.CONTROL + "t");