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
这一工作。 但是,由于它等待了30秒钟,每次都要尝试和找到一线。 我试图略微缩短时间,但这似乎只是一个框架定位器的选择吗? 是否有办法可以:(a) 减少这次行动的时间,或(b) 人工停止两秒钟的文字,然后立即进行检查。 类似:
time.sleep(2)
if *check for iframe* == False:
continue
else:
*click on button*