Skip to content
Advertisement

How to wait for invisibility of an element through PageFactory using Selenium and Java

Is there a way to wait for an element not present in Selenium using PageFactory annotations?

When using:

JavaScript

to locate the element, and then:

JavaScript

I would get:

JavaScript

I am able to do what I need by using:

JavaScript

However, I would like to be able to use the PageFactory annotations in order to keep the framework consistent. Is there a way to do this?

Advertisement

Answer

invisibilityOfElementLocated is expecting a locator but you are sending a web-element and that is why it is throwing an error. You can perform the operation by checking the webelement list by using:

JavaScript

Updated Answer:
If you want to check that the element is not present on the page then you can check its list size is equal to 0 or not, as its list size will be 0 when its not displayed on the UI.

You can get the list of the element by using:

JavaScript

And you can check the list size equals to 0 by using:

JavaScript

And this would not give NoSuchElement exception as well.

User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement