Company logo
  • Jobs
  • Bootcamp
  • About Us
  • For professionals
    • Home
    • Jobs
    • Courses
    • Questions
    • Teachers
    • Bootcamp
  • For business
    • Home
    • Our process
    • Plans
    • Assessments
    • Payroll
    • Blog
    • Sales
    • Calculator

0

338
Views
IgnoreExceptionTypes does not work (C# Webdriver)

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.

9 months ago · Santiago Trujillo
1 answers
Answer question

0

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.

9 months ago · Santiago Trujillo Report
Answer question
Find remote jobs