Time for action – working with multiple windows - Selenium

Working with multiple browser windows can be one of the most difficult things to do within a Selenium Test. This is down to the fact that the browser needs to allow Selenium to programmatically know how many child browser processes have been spawned.

In the following examples we shall see the tests click on an element on the page which will cause a new window to appear. If you have a pop-up blocker running, it may be a good idea to disable it for this site while you work through these examples.

  1. Open up Selenium IDE and go to the Chapter(Getting Started with Selenium IDE) page on the site.

  2. Click on one of the elements on the page that has the text Click this link to launch another window. This will cause a small window to appear.

  3. Verify the text in the popup by right-clicking and selecting Verify Text id=popup text within the popup window.

  4. Once the window has loaded, click on the Close the Window text inside it.

  5. Add a verify command for an element on the page. Your test should now look like the following screen shot:

    Sometimes Selenium IDE will add a click And Wait instead of a click command.This is because it notices that the page has to unload. If this happens just change the click And Wait to a click so that it does not cause a timeout in the test.

What just happened?

In the test script we can see that it has clicked on the item to load the new window and then has inserted a wait For PopUp. This is so that your test knows that it has to wait for a web server to handle the request and the browser to render the page. Any commands that require a page to load from a web server will have a wait For command.

The next command is the select Window command. This command tells Selenium IDE that it will need to switch context to the window, called popup window, and will execute all the commands that follow in that window unless told otherwise by a later command.

Once the test has finished with the popup window, it will need to return to the parent window from where it started. To do this we need to specify null as the window. This will force the select Window to move the context of the test back to its parent window.


All rights reserved © 2018 Wisdom IT Services India Pvt. Ltd DMCA.com Protection Status

Selenium Topics