问题描述
考虑一下:
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()
?
推荐答案
你可以同时使用 presenceOfElementLocated
或 visibilityOfElementLocated
获取值
.
但从性能角度来看,我猜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.
使用
presenceOfElementLocated
当你不关心是否元素可见与否,您只需要知道它是否在页面上.
use
presenceOfElementLocated
when you don't care whether if elementvisible or not, you just need to know if it's on the page.
使用 visibilityOfElementLocated
当您需要查找元素时也应该可见.
use visibilityOfElementLocated
when you need to find element whichshould be also visible.
希望能帮到你..:)
这篇关于VisibilityOfElementLocated 与 PresenceOfElementLocated的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!