lecture 18 of 220 completed

Frames and iframes

An iframe is a separate document inside the page. Your selectors cannot cross into it until you switch context.

What you'll learn

  • Why a correct selector can still find nothing
  • How to switch into a frame and back out
  • Where iframes actually show up in real apps

A tester spent an afternoon on a payment form. The card field was visibly on the screen. Every selector she tried returned nothing. She checked the spelling twenty times.

The field was inside an iframe, and that is one of the most confusing failures in Selenium precisely because everything looks correct.

An iframe is a whole separate document embedded in the page. It has its own DOM. When you search for an element, Selenium searches the document it is currently focused on, and by default that is the main page. Elements inside a frame are invisible to that search, even though they are visible to you.

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 →