本文介绍了Python Selenium Webdriver检查元素是否不存在需要时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在几次GUI操作后尝试验证一些按钮不存在(预期不存在).我正在使用find_element_by_xpath(),但是它非常慢.有什么办法解决超时问题吗?
Trying to verify after few GUI operations some button does not exist (expected not to be present). I am using find_element_by_xpath() but its very slow. Any solution of timeout?
推荐答案实际上,如果找不到指定的元素,WebDriver的find_element方法将等待元素的隐式时间.
Actually WebDriver's find_element method will wait for implicit time for the element if the specified element is not found.
WebDriver中没有可检查的预定义方法,例如isElementPresent().您应该为此编写自己的逻辑.
There is no predefined method in WebDriver like isElementPresent() to check. You should write your own logic for that.
逻辑
public boolean isElementPresent() { try { set_the_implicit time to zero find_element_by_xpath() set_the_implicit time to your default time (say 30 sec) return true; } catch(Exception e) { return false; } }请参阅: goo.gl/6PLBw
更多推荐
Python Selenium Webdriver检查元素是否不存在需要时间
发布评论