lecture 17 of 220 completed

Windows and tabs

Selenium looks at one window at a time. A link that opens a tab leaves your test looking at the wrong one.

What you'll learn

  • Why a new tab leaves your test looking at the old one
  • How to switch windows and get back safely
  • When checking the link is enough

A test clicks "View invoice" and then looks for the invoice number. It fails. The invoice opened in a new tab, and Selenium is still pointed at the old one.

This is a rule worth stating plainly: the driver has exactly one window in focus at any time. Opening a tab does not move that focus. You move it yourself.

Selenium identifies windows with handles, which are just opaque id strings.

members only

Keep reading with the full course

The Foundations track and the first 5 lectures of each framework are free. This lecture is part of the paid course, which unlocks every lecture, all three frameworks, and downloads.

See the options →