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

Provided the info for this tip.

Contributed the initial Java code for this tip.

Contributed the Python code for this tip.

Python code review

Python code review

Contributed the initial C# code for this tip.

Contributed the Selenide code for this tip.
Authors

Original creator of Elemental Selenium

Current maintainer of Elemental Selenium