Best Python code snippet using playwright-python
test_locators.py
Source:test_locators.py
...360 locator.set_checked(True)361 assert page.evaluate("checkbox.checked")362 locator.set_checked(False)363 assert page.evaluate("checkbox.checked") is False364def route_iframe(page: Page) -> None:365 page.route(366 "**/empty.html",367 lambda route: route.fulfill(368 body='<iframe src="iframe.html"></iframe>', content_type="text/html"369 ),370 )371 page.route(372 "**/iframe.html",373 lambda route: route.fulfill(374 body="""<html>375 <div>376 <button>Hello iframe</button>377 <iframe src="iframe-2.html"></iframe>378 </div>379 <span>1</span>380 <span>2</span>381 </html>""",382 content_type="text/html",383 ),384 )385 page.route(386 "**/iframe-2.html",387 lambda route: route.fulfill(388 body="<html><button>Hello nested iframe</button></html>",389 content_type="text/html",390 ),391 )392def test_locators_frame_should_work_with_iframe(page: Page, server: Server) -> None:393 route_iframe(page)394 page.goto(server.EMPTY_PAGE)395 button = page.frame_locator("iframe").locator("button")396 button.wait_for()397 assert button.inner_text() == "Hello iframe"398 button.click()399 assert (400 repr(page.frame_locator("iframe"))401 == f"<FrameLocator frame=<Frame name= url='{server.PREFIX}/empty.html'> selector='iframe'>"402 )403def test_locators_frame_should_work_for_nested_iframe(404 page: Page, server: Server405) -> None:406 route_iframe(page)407 page.goto(server.EMPTY_PAGE)408 button = page.frame_locator("iframe").frame_locator("iframe").locator("button")409 button.wait_for()410 assert button.inner_text() == "Hello nested iframe"411 button.click()412def test_locators_frame_should_work_with_locator_frame_locator(413 page: Page, server: Server414) -> None:415 route_iframe(page)416 page.goto(server.EMPTY_PAGE)417 button = page.locator("body").frame_locator("iframe").locator("button")418 button.wait_for()419 assert button.inner_text() == "Hello iframe"420 button.click()421def route_ambiguous(page: Page) -> None:422 page.route(423 "**/empty.html",424 lambda route: route.fulfill(425 body="""426 <iframe src="iframe-1.html"></iframe>427 <iframe src="iframe-2.html"></iframe>428 <iframe src="iframe-3.html"></iframe>429 """,...
LambdaTest’s Playwright tutorial will give you a broader idea about the Playwright automation framework, its unique features, and use cases with examples to exceed your understanding of Playwright testing. This tutorial will give A to Z guidance, from installing the Playwright framework to some best practices and advanced concepts.
Get 100 minutes of automation test minutes FREE!!