1. Anuncie Aqui ! Entre em contato fdantas@4each.com.br

[Python] (NODRIVER) how to send "Enter" shortcut key

Discussão em 'Python' iniciado por Stack, Outubro 7, 2024.

  1. Stack

    Stack Membro Participativo

    I've been trying to get my bot to press the Enter key after going to the website "en.key-test.ru". It basically tracks if a key is pressed. The strange thing is, the code prints successfully right after attempting the Enter key press, but the action itself doesn't seem to work. When I do it manually, it works fine. Has anyone faced a similar issue or have any insights on why the bot isn't triggering the key press correctly?

    import string
    import time
    import asyncio
    import requests
    import nodriver as uc
    from nodriver.cdp import fetch

    async def website():
    # Start the browser
    browser = await uc.start()
    main_tab = await browser.get("draft:,")

    try:
    tab = await browser.get("https://en.key-test.ru/")
    await asyncio.sleep(4)
    await tab.send(uc.cdp.input_.dispatch_key_event(
    type_="rawKeyDown",
    windows_virtual_key_code=13,
    ))
    print('Entered')
    await asyncio.sleep(5) # Wait to see if it worked
    else:
    print("Field not found.")
    return

    if __name__ == "__main__":
    uc.loop().run_until_complete(website())

    Continue reading...

Compartilhe esta Página