I've been trying to get my bot to press the Enter key and type in a box after going to the website "www.keyboardtester.com". It basically tracks if a key is pressed. I believe the bot cant find the iframe. I checked docs and support on git, but cant seem to figure it out. When I do it manually, it works fine. Has anyone faced a similar issue or have any insights on why the bot isn't finding the iframe?
#๐ [NODRIVER] how to send shortcut keys in an iframe
5 messages ยท Page 1 of 1 (latest)
@spice spindle
Remember to:
- Ask your Python question, not if you can ask or if there's an expert who can help.
- Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
- Explain what you expect to happen and what actually happens.
:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.
Closes after a period of inactivity, or when you send !close.
import time
import asyncio
import nodriver as uc
from nodriver.cdp import fetch
from nodriver import *
async def website():
browser_args = ['--disable-web-security', '--disable-site-isolation-trials']
browser = await uc.start(browser_args=browser_args)
try:
tab = await browser.get("https://iframetester.com/?url=https://www.keyboardtester.com/tester.html")
await asyncio.sleep(5)
# Select the iframe
iframes = await tab.select('iframe')
if iframes:
iframe = iframes[0]
# Now find the textarea inside the iframe
input = await tab.find("//textarea[@id='testarea']")
if input:
await asyncio.sleep(1)
await input.send_keys("Test")
# Simulate pressing Enter
await input.send(uc.cdp.input_.dispatch_key_event(
type_="rawKeyDown",
windows_virtual_key_code=13,
))
await input.send(uc.cdp.input_.dispatch_key_event(
type_="rawKeyUp",
windows_virtual_key_code=13,
))
print('Entered')
else:
print("Unable to find text inside the iframe.")
else:
print("No iframes found on the page.")
await asyncio.sleep(10)
except Exception as e:
print(f"Error: {e}")
finally:
browser.stop()
if __name__ == "__main__":
uc.loop().run_until_complete(website())
Error:
Error: time ran out while waiting for text: //textarea[@id='testarea']
X-path is correct, I believe Iframe isnt found.
@spice spindle
This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.