0

I'm building an app that use selenium for some automation task, but the issue is that the site I am inspecting, after selenium clicks on a link, the link is open in a new tab, not in the sameone.

So when I try to access to the elements in the new tab, It's like selenium is still accesing to the previous page event the new tab is the active one in the browser.

Faabass
  • 1,394
  • 8
  • 29
  • 58

1 Answers1

1

Use WebDriver's getWindowHandles() command to switch between the windows.

String currentWindow = driver.getWindowHandle();

for(String newWindows : driver.getWindowHandles()){
    driver.switchTo().window(newWindows);
}

// perform some action in new window and close it
driver.close();

// switch to default window or current window
driver.switchTo().window(currentWindow);
// OR
driver.switchTo().defaultContent();
NarendraR
  • 7,577
  • 10
  • 44
  • 82