Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WebDriverWait does not ignore exceptions

I am using the most current Chrome and Webdriver 2.33 and am having some issues with IgnoreExceptionTypes. In the below code webdriver will wait like I expect it too but it will not actually ignore the exceptions:

WebDriverWait wait = new WebDriverWait(driver, TimeSpan.FromSeconds(8));
wait.IgnoreExceptionTypes(
    typeof(WebDriverTimeoutException),
    typeof(NoSuchElementException)
);  
wait.Until(ExpectedConditions.ElementIsVisible(By.XPath(firstResultX)));

The code is in a try/catch, I tried moving it outside of the try/catch and received the same issue. I am not sure where to go from here, any help would be appreciated.

like image 296
hhcib Avatar asked Aug 21 '13 15:08

hhcib


People also ask

Which of the following exceptions should not be ignored via FluentWait?

With FluentWait, we can define the exceptions' classes from which we will want to ignore during the waiting time. In our case, we will want to ignore the class NoSuchElementException. If we do not ignore it – The wait will not occur and we will immediately receive that exception.

How do I ignore exceptions in Selenium?

Put a try-except block around the piece of code that produced that error. Show activity on this post. Show activity on this post. It looks like the browser rendering engine or Javascript engine is using the element and it is blocking other external operations on this element.

What is exception thrown by WebDriverWait if element not found?

The exception occurs when WebDriver is unable to find and locate elements. Usually, this happens when tester writes incorrect element locator in the findElement(By, by) method. In this case, the exception is thrown even if the element is not loaded. Avoiding-And-Handling: Try giving a wait command.

What is the use of WebDriverWait?

It is applied on certain element with defined expected condition and time. This wait is only applied to the specified element. This wait can also throw exception when element is not found.


1 Answers

You can use FluentWaits.

Wait<WebDriver> wait = new FluentWait<WebDriver>(getDriverInstance())
                .withTimeout(timeoutSeconds, TimeUnit.SECONDS)
                .pollingEvery(sleepMilliSeconds, TimeUnit.SECONDS)
                .ignoring(NoSuchElementException.class);

wait.until(<Your expected condition clause.>);

Let me know if this does not solves your problem.

like image 69
Mrunal Gosar Avatar answered Sep 27 '22 18:09

Mrunal Gosar