简体   繁体   English

Selenium Python:如何等待div出现,做东西,然后再等等等?

[英]Selenium Python: How to wait for div to appear, do stuff, then wait again and so on?

I have a website where I need to automate some actions.我有一个网站,我需要在其中自动执行一些操作。

Every time a customer does a purchase, a div with an input and a submit button appears.每次客户进行购买时,都会出现一个带有输入和提交按钮的 div。 On that div I need to enter a value and click submit.在那个 div 上,我需要输入一个值并单击提交。 The div then closes until the next purchase appears in the same div. div 然后关闭,直到下一次购买出现在同一个 div 中。 I need to do the same actions, and so on.我需要做同样的动作,等等。

It's indefinite.它是无限期的。

I already found some solutions that point to the direction: Selenium - wait until element is present, visible and interactable我已经找到了一些指向方向的解决方案: Selenium - 等到元素出现,可见且可交互

WebDriverWait(browser, 20).until(EC.presence_of_element_located((By.CSS_SELECTOR, ".reply-button"))).click()

But I can't provide a specific time to wait.但我无法提供具体的等待时间。 I need a solution that keeps going in a loop indefinitely and progress all purchases throughout the day我需要一个解决方案,可以无限期地循环并全天进行所有购买

Every solution that I find solves the problem that the website takes time to load.我找到的每个解决方案都解决了网站加载需要时间的问题。 But I have a completely different problem underlying.但我有一个完全不同的问题。 I need to wait for a purchases to happen.我需要等待购买发生。 So I can't set a specific time to wait.所以我无法设定具体的等待时间。 It could be indefinite.它可能是无限期的。

What Selenium function could help me -in a best practice way- with my problem?什么 Selenium function 可以以最佳实践方式帮助我解决我的问题?

You can give some more time to webdriver.你可以给 webdriver 更多的时间。

WebDriverWait(browser, 30).until(EC.presence_of_element_located((By.CSS_SELECTOR, ".reply-button"))).click()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM