I\'m working with Selenium Automation. In this, When i click a link in a current window, a new window opens. I just want to switch the control to the new window. But i can\'
Here is the best methods to switch in window using index and title. you can add in base class and use it frequently.
public void switchToWindow(String windowTitle) {
Set windows = driver.getWindowHandles();
for (String window : windows) {
driver.switchTo().window(window);
if (driver.getTitle().contains(windowTitle)) {
return;
}
}
}
public void switchToWindow(int index) {
Set windows = driver.getWindowHandles();
int totalWin= windows.size();
String winTitle = null;
for(int i=0;i