This query consists of 2 related questions. I need to wait for an element to be invisible before I go to next step, hence I tried to define a custom method as below:
public void waitToDisappear(long timeOutInSeconds, WebElement element) {
WebDriverWait wait = new WebDriverWait(driver, timeOutInSeconds);
wait.ignoring(org.openqa.selenium.NoSuchElementException.class);
wait.until(ExpectedConditions.invisibilityOf(element));
}
When I call this method as common.waitToDisappear(5, <WebElement>);, I'm getting Caused by: org.openqa.selenium.NoSuchElementException: no such element: Unable to locate element:.
However, if I use locator method new WebDriverWait(world.driver, 5).until(ExpectedConditions.invisibilityOfElementLocated((By.xpath(someXpath)))), it is working fine without any exception.
Question-1: NoSuchElementException is ignored in Selenium implementation of invisibilityOfElementLocated(), but not in invisibilityOf(). Is there is any reason for this? But, I think this is why I'm getting exception. How do I wait for an element(not locator) to be disappeared?
Question-2: Why am I getting NoSuchElementException even though I'm using wait.ignoring(org.openqa.selenium.NoSuchElementException.class);. Is it the right way of using wait.ignoring? It seems that wait.ignoring() is not doing anything here.
Thanks in advance for your answers.