Skip to main content

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


We hope this was a helpful guide on how to work with and switch between multiple windows.

Happy Testing!

Special Thanks

Jim Evans
Provided the info for this tip.
Roman Isko
Contributed the initial Java code for this tip.
Mike Millgate
Contributed the Python code for this tip.
Isaul Vargas
Python code review
Peter Bittner
Python code review
Jonathan Taylor
Contributed the initial C# code for this tip.
Andrei Solntsev
Contributed the Selenide code for this tip.


Dave Piacente
Original creator of Elemental Selenium
Diego Molina
Current maintainer of Elemental Selenium