Ignore ExceptionTypes not working (C # Webdriver)

I found that in C# whether the WebDriverWait class or the DefaultWait class , the IgnoreExceptionTypes method does not seem to work anyway.

those. in any case, when working with my page, a StaleElementReferenceException is StaleElementReferenceException , despite the fact that I instruct 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 seems to be very little on the Internet about using this particular method, while others believe that it also does not work without any workarounds.

+6
source share
1 answer

IgnoreExceptionTypes will only wait until the timeout expires. I am using DefaultWait and, as you expected, returns null. Is not. When the timeout is reached, it throws an exception. Therefore, I included it in a try catch in order to handle the exception appropriately during a timeout.

+3
source

All Articles