0

I want to switch the tabs from one tab to other and need to switch back on previous tab.

So, please guide me for same.

Amit Pal
  • 177
  • 3
  • 11

1 Answers1

0
 String winHandleBefore = driver.getWindowHandle();

    // Perform the click operation that opens new window

    driver.findElement(By.xpath("yourElement").click());
    // Switch to new window opened
    for(String winHandle : driver.getWindowHandles()){
    driver.switchTo().window(winHandle);
    }

    // Perform the actions on new window

    // Close the new window, if that window no more required
    driver.close();

    // Switch back to original browser (first window)
    driver.switchTo().window(winHandleBefore);
Reez0
  • 2,512
  • 2
  • 17
  • 39