Name 5 different exceptions you had in selenium web driver and mention
.What instance you got it and how do you resolve it?
·
WebDriverException
·
NoAlertPresentException
·
NoSuchWindowException
·
NoSuchElementException
·
TimeoutException
• WebDriverException
WebDriver Exception comes when we try to
perform any action on the non-existing
driver.
WebDriver driver = new
InternetExplorerDriver();
driver.get("http://google.com");
driver.close();
driver.quit();
•
NoAlertPresentException
When we try to perform
an action i.e., either accept() or dismiss() which is not required
at a required place;
gives us this exception.
try{
driver.switchTo().alert().accept();
}
catch
(NoAlertPresentException E){
E.printStackTrace();
}
•
NoSuchWindowException
When we try to switch to an window which is
not present gives us this exception:
WebDriver driver = new
InternetExplorerDriver();
driver.get("http://google.com");
driver.switchTo().window("Yup_Fail");
driver.close();
In the above snippet,
line 3 throws us an exception, as we are trying to switch to an
window that is not
present.• NoSuchFrameException
• Similar to Window
exception, Frame exception mainly comes during switching between
the frames.
WebDriver driver = new
InternetExplorerDriver();
driver.get("http://google.com");
driver.switchTo().frame("F_fail");
driver.close();
In the above snippet,
line 3 throws us an exception, as we are trying to switch to an
frame that is not
present.
•
NoSuchElementException
This exception is thrown when we WebDriver
doesn’t find the web-element in the DOM.
WebDriver driver = new
InternetExplorerDriver();
driver.get("http://google.com");
driver.findElement(By.name("fake")).click();
• TimeoutException
Thrown when a command does not complete in
enough time.
All the above
exceptions were handled using try catch exceptions.
No comments:
Post a Comment