Selecting a newly opened window using selenium will me a nightmare for all who are trying to automate using selenium.
Selenium provides selectWindow(windowID) method for handling this situation. In most cases we wont get the window id. So we are forced to go with other parameters like "title= Title of newly opened page" or "name = Name of Window" etc. Most often window.open method will be provided with a window name. If so we can go for selectWindow("name=window_Name").
If both the above cases cannot be applied go for the code snippet given below.
Selenium selenium;
String new_Window = this.driver.getWindowHandle();
Set<String> wh1 = driver.getWindowHandles();
selenium.click("Link of window");
Set<String> wh2 = driver.getWindowHandles();
wh2.removeAll(wh1);
new_Window = (String) wh2.toArray()[0];
selenium.selectWindow(new_Window);
No comments:
Post a Comment