I have found that in C#
whether using the WebDriverWait class
or the DefaultWait class
, in either case the IgnoreExceptionTypes
method appears not to work.
I.e. in either case when running against my page a StaleElementReferenceException
is thrown despite the fact I am instructing the code to ignore these exceptions.
WebDriverWait
example :
public void WaitElementToBeClickable(IWebElement element)
{
var wait = new WebDriverWait(Driver, TimeSpan.FromSeconds(60));
wait.IgnoreExceptionTypes(typeof(NoSuchElementException), typeof(StaleElementReferenceException));
wait.Until(ExpectedConditions.ElementToBeClickable(element));
}
DefaultWait example :
public IWebElement SafeWaitForDisplayed(IWebElement webElement) {
var w = new DefaultWait<IWebElement>(webElement);
w.Timeout = TimeSpan.FromSeconds(30);
w.IgnoreExceptionTypes(typeof(NoSuchElementException), typeof(StaleElementReferenceException));
return w.Until(ctx =>
{
var elem = webElement;
if (elem.Displayed)
return elem;
else
return null;
});
}
Any suggestions gratefully received. There appears to be very little on the web about usage of this particular method and others have found it not to work also with no workarounds suggested.
The IgnoreExceptionTypes
will only last throughout the wait until it times out. I am using the DefaultWait
and like you was expecting it to return null. It does not. When the timeout is reached it will throw the exception. Consequently I have enclosed it in a try catch to handle the exception appropriately on timeout.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With