Best Python code snippet using playwright-python
test_focus.py
Source:test_focus.py
...16 await page.set_content("<div id=d1 tabIndex=0></div>")17 assert await page.evaluate("() => document.activeElement.nodeName") == "BODY"18 await page.focus("#d1")19 assert await page.evaluate("() => document.activeElement.id") == "d1"20async def test_should_emit_focus_event(page):21 await page.set_content("<div id=d1 tabIndex=0></div>")22 focused = []23 await page.expose_function("focusEvent", lambda: focused.append(True))24 await page.evaluate("() => d1.addEventListener('focus', focusEvent)")25 await page.focus("#d1")26 assert focused == [True]27async def test_should_emit_blur_event(page):28 await page.set_content(29 "<div id=d1 tabIndex=0>DIV1</div><div id=d2 tabIndex=0>DIV2</div>"30 )31 await page.focus("#d1")32 focused = []33 blurred = []34 await page.expose_function("focusEvent", lambda: focused.append(True))...
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!!