RE: How to open new tab in chromedriver? The following code is not working for chrome driver. Any other ways


Driver().findElement(By.cssSelector("body")).sendKeys(Keys.CONTROL+"t");

Add Comment
4 Answers

Chrome driver for selenium – 2.25
Google Chrome version – 54.0.2840

// Open link in same window but in next tab
String selectLinkOpeninNewTab = Keys.chord(Keys.CONTROL, Keys.ENTER);
driver.findElement(By.xpath(“Your Xpath Here”)).sendKeys(selectLinkOpeninNewTab);

// Switch focus to next tab
Robot robot = new Robot();
robot.keyPress(KeyEvent.VK_CONTROL);
robot.keyPress(KeyEvent.VK_TAB);

Below statement to change the focus to the new tab does not work on Chrome browser but it works for Firefox.
Actions act = new Actions(driver);
act.sendKeys(Keys.chord(Keys.CONTROL,Keys.TAB)).perform(); //switch to new tab by pressing control+tab

Therefore, use the code provided above using Robot class from awt package.

Default Answered on November 2, 2016.
Add Comment

Your Answer

By posting your answer, you agree to the privacy policy and terms of service.