04
Oct
Switching between tabs in Selenium
Switching between tabs in Selenium
//Get handle to Current window tab.
String mainWindowHandle = driver.getWindowHandle();
//Perform action which opens a new tab window in browser.
//Get the list of window handles
ArrayList tabs = new ArrayList (driver.getWindowHandles());
System.out.println(tabs.size());
//Use the list of window handles to switch between windows
driver.switchTo().window(tabs.get(0));
//Switch back to original window
driver.switchTo().window(mainWindowHandle);
0 comments