MCPcopy Create free account
hub / github.com/microsoft/playwright-python / captureLastKeydown

Function captureLastKeydown

tests/async/test_keyboard.py:22–45  ·  view source on GitHub ↗
(page: Page)

Source from the content-addressed store, hash-verified

20
21
22async def captureLastKeydown(page: Page) -> JSHandle:
23 lastEvent = await page.evaluate_handle(
24 """() => {
25 const lastEvent = {
26 repeat: false,
27 location: -1,
28 code: '',
29 key: '',
30 metaKey: false,
31 keyIdentifier: 'unsupported'
32 };
33 document.addEventListener('keydown', e => {
34 lastEvent.repeat = e.repeat;
35 lastEvent.location = e.location;
36 lastEvent.key = e.key;
37 lastEvent.code = e.code;
38 lastEvent.metaKey = e.metaKey;
39 // keyIdentifier only exists in WebKit, and isn't in TypeScript's lib.
40 lastEvent.keyIdentifier = 'keyIdentifier' in e && e.keyIdentifier;
41 }, true);
42 return lastEvent;
43 }"""
44 )
45 return lastEvent
46
47
48async def test_keyboard_type_into_a_textarea(page: Page) -> None:

Calls 1

evaluate_handleMethod · 0.45

Tested by

no test coverage detected