How to switch to the new browser window, which opens after click on the button? (Java)

How to switch to the new browser window, which opens after click on the button? (Java)

In order to change to a newly opened tab, use window handles as shown in the following script. Window handles are used to store the currently opened windows and to tell the WebDriver which one to be focused on.

String selectLinkOpeninNewTab = Keys.chord(Keys.CONTROL, Keys.RETURN);
driver.findElement(By.xpath("//a[strong[.='English']]")).sendKeys(selectLinkOpeninNewTab);

// Switch to next tab
for (String windowHandle : driver.getWindowHandles()) {
  driver.switchTo().window(windowHandle);
}

Leave a reply

Your email address will not be published. Required fields are marked*

CAPTCHA
This question is for testing whether or not you are a human visitor and to prevent automated spam submissions.
3 + 13 =

Solve this simple math problem and enter the result. E.g. for 1+3, enter 4.