1

I am trying to open a new tab using Selenium Webdriver and Java, and have used the below code, but it is not opening any new tab and no error message is displayed during the run.

Actions act = new Actions(driver);      
act.keyDown(Keys.CONTROL).sendKeys("t").keyUp(Keys.CONTROL).build().perform();

Using the above code I am trying to open a new tab by pressing CTRL+T from keyboard. Please help me.

Evan Knowles
  • 7,426
  • 2
  • 37
  • 71
Arijit Biswas
  • 81
  • 1
  • 3
  • 16

1 Answers1

1

try this

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

or use

((JavascriptExecutor)driver).executeScript("window.open();");
iamsankalp89
  • 4,607
  • 2
  • 15
  • 36