简体   繁体   English

Selenium Webdriver find_element_by_xpath需要时间

[英]Selenium webdriver find_element_by_xpath takes time

If element does not exist on the page find_element_by_xpath() takes too much time hanging the test execution. 如果页面上不存在element,则find_element_by_xpath()会花费太多时间挂起测试执行。 Is there any way to set timeout to find_element_by_xpath() function in python? 有什么办法可以在python中为find_element_by_xpath()函数设置超时时间?

You can set an implicit wait using this code - 您可以使用以下代码设置隐式等待 -

ff = webdriver.Firefox()
ff.implicitly_wait(10) # seconds

This makes the WebDriver wait for 10 secs before raising an error when you try to find an element on the webpage. 当您尝试在网页上查找元素时,这会使WebDriver等待10秒钟,然后引发错误。

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

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