Python Selenium Webdriver检查元素是否不存在需要时间

编程入门 行业动态 更新时间:2024-10-26 14:38:00
本文介绍了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检查元素是否不存在需要时间

本文发布于:2023-11-27 15:47:19,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1638627.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:不存在   元素   时间   Python   Selenium

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!