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.

4

1 Answer 1

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();");
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.