Selenium WebDriver 4

Switch into an iframe by element

Medium70 pts~25 min
  • iframes
  • WebElement frames
  • Validation
Practice app · Secure Checkout

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

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

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

Objective

Locate the payment iframe as a WebElement, switch into it and exercise both the validation error and a successful payment.

Your task

  1. 1Find the iframe element with the CSS selector #payment-frame (or name="payment").
  2. 2Switch into the frame by passing that element (not an index or a string).
  3. 3Type 4242 into #card-number, click #pay-button and assert #pay-result reads “Card number must be 16 digits”.
  4. 4Clear #card-number, type 4242424242424242, click #pay-button again and assert “Payment authorized”.

Acceptance criteria

  • The frame is selected by WebElement
  • #pay-result inside #payment-frame shows “Payment authorized”
  • At least 2 assertions pass (error, then success)

Selenium WebDriver 4 · Selenium · Frames, windows & tabs