0

In selenium 3.141.59 I am trying to open a new Tab using

 Actions action = new Actions(driver);
 action.keyDown(Keys.CONTROL).sendKeys(Keys.TAB).build().perform(); 
and  
driver.findElement(By.cssSelector("body")).sendKeys(Keys.CONTROL +"t"); 

I'm not able to open new Tab

EdChum
  • 376,765
  • 198
  • 813
  • 562
  • that might be duplicate.. https://stackoverflow.com/questions/17547473/how-to-open-a-new-tab-using-selenium-webdriver refer this for your answer. – Dhru 'soni May 15 '19 at 10:41

2 Answers2

1

You can try with this code :

((JavascriptExecutor) driver).executeScript("window.open('"+url+"','_blank');");

URL is a variable, You can use your own or else paste the value of it.

cruisepandey
  • 28,520
  • 6
  • 20
  • 38
0

This might help! this opens up the new tab and control passes to the newly opened tab.

 WebDriver driver = new FirefoxDriver();
       driver.get("http://www.google.com/");
       driver.manage().timeouts().pageLoadTimeout(30, TimeUnit.SECONDS);
       System.out.println(driver.getTitle());
       Thread.sleep(3000L);

       WebElement element = driver.findElement(By.linkText("Gmail"));

       Actions action = new Actions(driver);

       action.moveToElement(element);


       action.keyDown(Keys.CONTROL);
       action.click();

       action.keyDown(Keys.CONTROL).build().perform();
       Thread.sleep(2000L);
       ArrayList<String> list = new ArrayList<String>(driver.getWindowHandles());
       driver.switchTo().window(list.get(1));

       driver.get("http://www.yahoo.com/");
       Thread.sleep(4000L);
       driver.close();