Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

VisibilityOfElementLocated Vs presenceOfElementLocated

Consider this:

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

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

like image 735
david hol Avatar asked Jun 26 '16 13:06

david hol


1 Answers

You can use both presenceOfElementLocated or visibilityOfElementLocated to get the value.

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.

So according to your case use of presenceOfElementLocated will be enough.

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.

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

Hope it will help you..:)

like image 81
Saurabh Gaur Avatar answered Sep 23 '22 23:09

Saurabh Gaur