VisibilityOfElementLocated 与 PresenceOfElementLocated [英] VisibilityOfElementLocated Vs presenceOfElementLocated

查看:31
本文介绍了VisibilityOfElementLocated 与 PresenceOfElementLocated的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

考虑一下:

val element = ...
String str = element.getAttribute("innerHTML")

所以,如果我只想获得这个 value 是否足以使用 presenceOfElementLocated() 而不是 visibilityOfElementLocated() ?>

So in case i only wants to get this value is it enough to use presenceOfElementLocated() instead of visibilityOfElementLocated() ?

推荐答案

你可以同时使用 presenceOfElementLocatedvisibilityOfElementLocated 获取.

但从性能角度来看,我猜presenceOfElementLocated 会稍微快一点,因为它只是检查 元素是否存在于页.这并不一定意味着该元素是可见的.而 visibilityOfElementLocated 必须检查元素是否存在于页面的 DOM 上并且可见.可见性是指元素不仅显示出来,而且高度和宽度都大于0.

But for the performance perspective, I would guess that presenceOfElementLocated will be slightly faster because it's just check that an element is present on the DOM of a page. This does not necessarily mean that the element is visible. while the visibilityOfElementLocated has to check that an element is present on the DOM of a page and visible. Visibility means that the element is not only displayed but also has a height and width that is greater than 0.

所以根据你的情况使用 presenceOfElementLocated 就足够了.

您可以考虑以下几点,根据您的用例选择合适的方法.

you can consider the following point to 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.

使用 visibilityOfElementLocated 当您需要查找元素时也应该可见.

use visibilityOfElementLocated when you need to find element which should be also visible.

希望能帮到你..:)

这篇关于VisibilityOfElementLocated 与 PresenceOfElementLocated的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆