Switch between two browser windows using Selenium WebDriver
selenium, webdriver
Solution
you can use following code to switch between windows based on the window title
private void handleMultipleWindows(String windowTitle) {
Set<String> windows = driver.getWindowHandles();
for (String window : windows) {
driver.switchTo().window(window);
if (driver.getTitle().contains(windowTitle)) {
return;
}
}
}
Similary you could use URL or some other criteria to switch windows.
Problem
I used Firefox Driver to open two URL's. Whenever I invoke driver, new firefox window is opened. I have to switch between these two windows. How can I do this?