Exception
Though there are many Exception classes under WebDriverException, we commonly see the below ones.
- NoSuchElementException
- NoSuchWindowException
- NoSuchFrameException
- NoAlertPresentException
- InvalidSelectorException
- ElementNotVisibleException
- ElementNotSelectableException
- TimeoutException
- NoSuchSessionException
- StaleElementReferenceException
Details:
ElementNotVisibleException: If selenium tries to find an element but the element is not visible within the page
NoAlertPresentException: If a user tries to handle an alert box but the alert is not present.
NoSuchAttributeException: While trying to get attribute value but the attribute is not available in DOM.
NoSuchElementException: This exception is due to accessing an element which is not available on the page.
WebDriverException: Exception comes when a code is unable to initialize WebDriver.
try { WebDriverWait wait = new WebDriverWait(driver, TimeSpan.FromSeconds( 10 )); wait.Until(ExpectedConditions. elementToBeClickable(By.id(”swift”)); try { Select dropdown = new Select(driver.findElement(By.id( "swift" ))); } catch (WebDriverException e) { System.out.println(“Exceptional case ”); } } catch (TimeOutException e) System.out.println(“WebDriver found that this element was not selectable.”); } |
try
{
WebDriverWait wait =
new
WebDriverWait(driver, TimeSpan.FromSeconds(
10
));
wait.Until(ExpectedConditions.visibilityOfElementLocated(By.id(”submit”));
try
{
driver.findElement(By.id(
"submit"
)).click();
}
catch
(WebDriverException e) {
System.out.println(“Exceptional
case
”);
}
}
catch
(TimeOutException e)
System.out.println(“WebDriver couldn’t find
this
element visible”);
}
{
Comments
Post a Comment