1

So I am scraping a site that has a random popup via an iframe sporadically appear as you scroll down the page. On the iframe there is a button to get rid of it. However, it's hard to be certain when it will appear. I can get round this by just having it try and find the iframe every time it tries to scroll down the page

try:
    page.frame_locator('#aframe').locator('button:has-text("click me")').click()
except:
    continue

This works. But it's super slow because it waits for 30 seconds to try and find the iframe each time. I tried just lowering the timeout, but this doesn't seem to be an option for a frame locator? Is there a way to either: (a) lower the timeout for this operation, or (b) manually stop the script for two seconds and then do an immediate check. Something like:

time.sleep(2)
if *check for iframe* == False:
    continue
else:
    *click on button*
2

1 Answer 1

0

Instead of having timeout to wait for iframe to appear, Try using waitFor(), It will wait until the iframe loaded.

    const clickme = page.frame_locator('#aframe').locator('button:has-text("click me")');
    await clickme.waitFor();
    await clickme.click()
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks for the answer. The problem with this is that OP wants to scroll and take actions between each check, so this would be too slow even if converted to Python. It's pretty much what they're already attempting. OP wants an instantaneous check, not a wait, which is that locators do.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.