• Jobs
  • About Us
  • professionals
    • Home
    • Jobs
    • Courses and challenges
  • business
    • Home
    • Post vacancy
    • Our process
    • Pricing
    • Assessments
    • Payroll
    • Blog
    • Sales
    • Salary Calculator

0

496
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.

about 3 years 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.

about 3 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Our process Sales
Legal
Terms and conditions Privacy policy
© 2025 PeakU Inc. All Rights Reserved.

Andres GPT

Recommend me some offers
I have an error