Reputation: 802
I am trying to test if a loading spinner is still on the page, so when it disappears I can check the other elements, but if I use something like:
WebDriverWait wait = new WebDriverWait(this.Driver, TimeSpan.FromMinutes(2));
wait.Until(driver => !driver.FindElement(By.CssSelector(css)).Displayed);
It throws NoSuchElementException
, I've had similar error when I try to check if element exists, without using !
and also it would throw an error in some other parts of the code.
It seems that the Until
is not working properly, since it waits 2 minutes to later throw an exception, and the element is just there.
Upvotes: 2
Views: 3504
Reputation: 1
If you need to wait till the element totally disappears from the DOM. You can use:
wait.Until(ExpectedConditions.ElementExists(By.XPath("your Xpath here")));
Element Exists
Is very good for checking pop-up messages existence on UI
Upvotes: 0
Reputation: 25076
The problem is that FindElement
will throw an exception when an element is not found, which is different to an element being found but not being displayed.
WebDriverWait
will allow you to specify exceptions you can ignore. So:
WebDriverWait wait = new WebDriverWait(this.Driver, TimeSpan.FromMinutes(2));
wait.IgnoreExceptionTypes(typeof(NoSuchElementException));
Aother option would be to be a bit more defensive in your code. Elements have multiple states, so something like a try/catch would work.
One final option would be to use ExpectedConditions
(a set of 'basic' conditions handcrafted for you to use):
wait.Until(driver => ExpectedConditions.ElementIsVisible(css));
Upvotes: 7