跳过等待网站计时器Selenium Python [英] Skip waiting for a website timer selenium Python
问题描述
我正在使用geckodriver在Python ide中运行Selenium.
I'm running Selenium in Python ide with geckodriver.
我要打开的网站的计时器为30秒,在这30秒之后,出现了一个按钮,我点击了该按钮.
The site I'm trying to open has a timer of 30 seconds that after this 30 seconds a button appears and I send a click on it.
我要问的是以下内容: 我可以以某种方式忽略/跳过/加快等待时间吗?
What I'm asking is the following: Can I somehow ignore/skip/speed up the waiting time?
现在我正在做的事情如下:
Right now what I'm doing is the following:
driver = webdriver.Firefox()
driver.get("SITE_URL")
sleep(30)
driver.find_element_by_id("proceed").click()
这是非常低效的,因为每次我运行代码来进行一些测试时,我都需要等待.
Which is very inefficient because every time I run the code to do some tests I need to wait.
Avi,谢谢.
更新: 我还没有找到克服障碍的方法,但是直到我这样做之前,我都在努力着力于下一个可以实现的进步:
UPDATE: I haven't found a way to get over the obstacle but until I do I'm trying to focus the next achievable progress:
<video class="jw-video jw-reset" disableremoteplayback="" webkit-playsinline="" playsinline="" preload="metadata" src="//SITE.SITE.SITE/SITE/480/213925.mp4?token=jbavPPLqNqkQT1SEUt4crg&time=1525458550" style="object-fit: fill;"></video>
(受审查站点的名称)
在每个页面中都有一个视频,所有视频都在"jw-video jw-reset"类下 我在按类使用find元素时遇到了麻烦,所以我使用了:
In each page there is a video, all the videos are under the class "jw-video jw-reset" I had trouble using find element by class so I used:
WebDriverWait(driver, 10).until(EC.presence_of_element_located((By.CSS_SELECTOR, "video[class='jw-video jw-reset']")))
它可以工作,但是我不知道如何选择元素的src ...
It works but I can't figure how to select the element's src...
推荐答案
根据您的代码试用版,您可以删除time.sleep(30)
并诱使 WebDriverWait 如下所示,以使该元素可点击: >
As per your code trial you can remove the time.sleep(30)
and induce WebDriverWait for the element to be clickable as follows :
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
# lines of code
WebDriverWait(driver, 30).until(EC.element_to_be_clickable((By.ID, "proceed"))).click()
注意:根据您的用例,将 WebDriverWait 实例配置为具有最大时间限制. expected_conditions
方法element_to_be_clickable()
将在元素可见并启用后立即返回 WebElement ,以便您可以单击它.
Note : Configure the WebDriverWait instance with the maximum time limit as per your usecase. The expected_conditions
method element_to_be_clickable()
will return the WebElement as soon as the element is visible and enabled such that you can click it.
这篇关于跳过等待网站计时器Selenium Python的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!