How to Work with Multiple Windows
The Problem
This tip will explain how to work with multiple windows in Selenium and switch between them.
Occasionally you'll run into a link or action in the application you're testing that will open a new window. In order to work with both the new and originating windows you'll need to switch between them.
On the face of it, this is a pretty straightforward concept. But there may be a small challenge to watch out for that you may find in some browsers and not others.
Let's step through a couple of examples to demonstrate.
Expected Behavior
- Open the browser
- Visit the page
- Click to open a new window
- Switch between the windows
- Check the page title to make sure the correct window is in focus
- Close the browser
Outro
We hope this was a helpful guide on how to work with and switch between multiple windows.
Happy Testing!
Special Thanks
![Jim Evans](https://pbs.twimg.com/profile_images/1187184424/Jim_Evans_casual_small_400x400.jpg)
Provided the info for this tip.
![Roman Isko](https://github.com/sturman.png)
Contributed the initial Java code for this tip.
![Mike Millgate](https://github.com/trabulmonkee.png)
Contributed the Python code for this tip.
![Isaul Vargas](https://github.com/isaulv.png)
Python code review
![Peter Bittner](https://github.com/bittner.png)
Python code review
![Jonathan Taylor](https://github.com/jtay2380.png)
Contributed the initial C# code for this tip.
![Andrei Solntsev](https://github.com/asolntsev.png)
Contributed the Selenide code for this tip.
Authors
![Dave Piacente](https://github.com/tourdedave.png)
Original creator of Elemental Selenium
![Diego Molina](https://github.com/diemol.png)
Current maintainer of Elemental Selenium