I have an issue when trying to test a web application with Selenium/Python. Basically I can't test elements of a pop-up window.
A scenario: I can test all elements for a page. But when I go to click on a button that opens up a small pop up box I can't test the elements on the popup. It's like the pop up isn't in focus or active.
I can test elements on the next page. For example click a button, brings me on to next page, and I can work with elements on the 'next' page. So it the problem seems to be popup specific.
I could post code but to be honest it might confuse at this stage. I may post code in a later post, thanks
How to handle popup windows in Selenium? Selenium has getWindowHandles () method , which returns all the window handle ids for all the open windows. This is stored in Set data structure in String data types.
There are usually three types of alerts or pop-ups you will face when creating an automated Selenium tests Remember, Selenium only works for browser automation. Any time you encounter a non-browser window — like an authentication pop-window — Selenium will not be able to recognize it since it is an OS-level dialog.
The Test steps for this scenario are: Enter a valid username, password, and log in. Click on the profile upload icon. Windows pop up appears wherein the path to upload a picture is entered. Until Step 3, Selenium Automation can handle it. When Windows pop up appears, the AutoIT script is used to automate that part.
Selenium has getWindowHandles () method , which returns all the window handle ids for all the open windows. This is stored in Set data structure in String data types. In order to navigate to a specific window, we need to traverse to the window we want to access with the iterator () method then switch to that window.
There is a property called switch_to
Q: How do I handle pop up windows?
A: WebDriver offers the ability to cope with multiple windows. This is done by using the WebDriver.switch_to.window(knownName)
method to switch to a window with a known name.
If the name is not known, you can use WebDriver.window_handles
to obtain a list of known windows.
You may pass the handle to switch_to.window(handleName)
For example I used driverName.switchTo.window(driverName.getWindowHandle())
to get a hold of popups for which I didn't want to look for names.
Additional references: http://code.google.com/p/selenium/wiki/FrequentlyAskedQuestions
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With