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