Selenium WebDriver 4

Switch into an iframe by index

Medium70 pts~25 min
  • iframes
  • Frame index
Practice app · Secure Checkout

A payment widget inside an iframe and a nested iframe structure.

Test URL
/lab/selenium-switch-into-an-iframe-by-index

Your starter code already declares TEST_URL — never hardcode a host.

Objective

Switch into the payment iframe by its numeric index, fill in the card form and confirm the payment is authorized.

Your task

  1. 1Open TEST_URL. The page has two top-level iframes: #payment-frame is first in the DOM (index 0), #outer-frame second.
  2. 2Switch to frame index 0 (switchTo().frame(0) / switch_to.frame(0) / SwitchTo().Frame(0)).
  3. 3Type 4242424242424242 into #card-number, 12/30 into #card-expiry and 123 into #card-cvc.
  4. 4Click #pay-button and assert #pay-result reads “Payment authorized”.

Acceptance criteria

  • The frame is selected by numeric index
  • #pay-result inside #payment-frame shows “Payment authorized”
  • At least 1 assertion passes

Selenium WebDriver 4 · Selenium · Frames, windows & tabs