Selenium + Python · Lesson 20 of 43
Module 20: Frames
Your task
Implement execute_in_frame(driver, frame_elem, action_fn):
Write it in the editor, then press Check answer (Ctrl + Enter).
frame_element = driver.find_element(By.ID, "payment-frame")
driver.switch_to.frame(frame_element)
# Interact inside frame:
driver.find_element(By.ID, "card-number").send_keys("4242 4242 4242 4242")
# Always switch back:
driver.switch_to.default_content()Elements inside iframes cannot be seen by standard find_element queries until you switch context into the frame. In this lesson, you will master switch_to.frame() and switch_to.default_content(). Let's master frames!
Part of the Selenium + Python course (Selenium with Python). Practice this concept live in the Selenium Online Compiler or explore our free automation practice form.
Use driver.switch_to.default_content() to jump all the way back to the main document.
Ready? Solve the task in the editor
Use Check answer to mark it complete. Hints are there if you need them.
___