VisibilityOfElementLocated Vs presenceOfElementLocated

david hol picture david hol · Jun 26, 2016 · Viewed 18.4k times · Source

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() ?

Answer

Saurabh Gaur picture Saurabh Gaur · Jun 27, 2016

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.

Hope it will help you..:)