Open pythonlw opened 2 months ago
waiting
You should read the CDP documentation and use low-level functions.
https://chromedevtools.github.io/devtools-protocol/tot/Input/#method-dispatchKeyEvent
async def send_keys(self, text: str):
"""
send text to an input field, or any other html element.
hint, if you ever get stuck where using py:meth:`~click`
does not work, sending the keystroke \\n or \\r\\n or a spacebar work wonders!
:param text: text to send
:return: None
"""
await self.apply("(elem) => elem.focus()")
[
await self._tab.send(cdp.input_.dispatch_key_event("char", text=char))
for char in list(text)
]
Port here #2019
import asyncio
import nodriver as uc
async def main():
browser = await uc.start()
tab_instance = await browser.get('https://www.google.com/')
await asyncio.sleep(1)
with tab_instance.keyboard as keyboard_instance:
await (await tab_instance.find('//input[1]')).click()
await keyboard_instance.type('Hello World!')
await keyboard_instance.down('Enter')
await asyncio.sleep(5)
if __name__ == '__main__':
# since asyncio.run never worked (for me)
uc.loop().run_until_complete(main())
Based on: https://github.com/pyppeteer/pyppeteer/blob/dev/pyppeteer/input.py Mattwmaster58
Mission accomplished, soldier! 🫡
here is how i handle it, add it right below the send_keys function:
async def send_crl_key(self, text: str): await self.apply("(elem) => elem.focus()") [ await self.tab.send(cdp.input.dispatch_keyevent( type='rawKeyDown', windows_virtual_key_code=ord(text.upper()), modifiers=2 )), await self.tab.send(cdp.input.dispatch_keyevent( type='keyUp', windows_virtual_key_code=ord(text.upper()), modifiers=2 )) ]
How to import the pyppeteer keyboard into nodriver @ultrafunkamsterdam