Playwright + Python · Lesson 21 of 37

0/37 done

Module 21: Frames

21. Seamless iframe Automation with frame_locator()

15 minlesson

Your task

Implement fill_frame_field(page, frame_selector, label, val):

  1. page.frame_locator(frame_selector).get_by_label(label).fill(val)

Write it in the editor, then press Check answer (Ctrl + Enter).

FrameLocator: Zero Context Switching

python
payment_frame = page.frame_locator("#stripe-frame")
payment_frame.get_by_label("Card number").fill("4242 4242 4242 4242")
payment_frame.get_by_label("CVC").fill("892")

Key Takeaways & Walkthrough Summary

Say goodbye to manual frame switching! In Playwright, frame_locator() seamlessly embeds frame navigation inside locator queries. In this lesson, you will master iframes and nested frames in Python. Let's master frames!

Part of the Playwright + Python course (Playwright with Python). Practice this concept live in the Playwright Online Compiler or explore our free automation practice form.

Common Doubts & Lesson Q&A

Do I need to switch back to the main document after frame_locator?

No! In Playwright, page and frame_locator instances are independent. You never have to switch back.

Ready? Solve the task in the editor

Use Check answer to mark it complete. Hints are there if you need them.

Python
Skip