Is there a way to wait for an element not present in Selenium using PageFactory annotations?
When using:
@FindBy(css= \'#loading-content\')
WebEleme
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:
wait.until(ExpectedConditions.invisibilityOfAllElements(Arrays.asList(pleaseWait)));
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:
@FindBy(css='#loading-content')
List pleaseWait;
And you can check the list size equals to 0 by using:
if(pleaseWait.size()==0){
System.out.println("Element is not visible on the page");
// Add the further code here
}
And this would not give NoSuchElement exception as well.