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.

full course

Keep reading with the full course

The Foundations track and the first lessons in each framework are free. This lesson needs full course access. A course plan includes all lessons for Playwright, Cypress and Selenium.

See course plans →