尝试在几次 GUI 操作后验证某些按钮不存在(预计不存在)。我正在使用 find_element_by_xpath() 但它非常慢。超时有什么解决办法吗?
最佳答案
实际上,如果找不到指定的元素,WebDriver 的 find_element 方法将等待该元素的隐式时间。
WebDriver 中没有像 isElementPresent() 这样的预定义方法来检查。您应该为此编写自己的逻辑。
逻辑
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;
}
}
关于Python Selenium Webdriver 检查元素是否不存在需要时间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12793390/