presence_of_element_located与visibility_of_element_located区别

selenium 问题:加了显性等待后,操作元素依然出错

 

背景: 用WebDriverWait时,一开始用的是presence_of_element_located,我对它的想法就是他就是用来等待元素出现。结果屡屡出问题。元素默认是隐藏的,导致等待过早的就结束了。

解决:去StackOverFlow查了一下,发现我应该用visibility_of_element_located。

原文:
复制代码
Well, I would guess that presenceOfElementLocated will be slighty faster because it's just check elements presence on the page while the visibilityOfElementLocated has to check the presenceand whether is element visible.

But I think it really doesn't matter from the performance perspective (what's the point if you save 0.001 second during this checking?), you better choose appropriate method depending on your use case.

use presenceOfElementLocated when you don't care whether if element visible or not, you just need to know if it's on the page
use visibilityOfElementLocated when you need to find element which should be also visible
Look at the documentation for more info.
复制代码

 

翻译:

我猜 presence_of_element_located 肯定会稍微快一点,因为它仅仅检查了页面是否存在该元素,而visibility_of_element_located还必须检查元素是否存在以及元素是否可见。

但是我认为从性能角度考虑,确实没啥影响。最好根据使用情况来选择正确的方法。

  • presence_of_element_located: 当我们不关心元素是否可见,只关心元素是否存在在页面中。
  • visibility_of_element_located: 当我们需要找到元素,并且该元素也可见。

转载于:https://www.cnblogs.com/sunny-sl/p/7201117.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值