1. Explain checked exceptions
These exceptions can be identified during compile time
Ex: FileNotFoundException, IOException
2. Explain unchecked exceptions.
These exceptions occurred during runtime.
Ex: ArrayIndexOutOfBoundException, NullPointerException, SQLException
3. What are the main two types of exceptions?
- checked exceptions
- unchecked exceptions
4.What are the exceptions given by Selenium and explain them
- ElementNotInteractableException : WebElement is present in the DOM but it is not in a state that is interact with
- NoAlertPresentexception : When the user tries to interact with an alert but alert is not present
- NoSuchElementException : When given element is cannot found in the DOM
- NoSuchwindowException : When given window is cannot found in the DOM
- TimeOutException : Command is not complete in enough time
- StaleElementReferenceException : The element looking for is no longer appears in the DOM
5.How to handle exceptions in Selenium?
- use the try-catch method
- try{} catch(){}
6. A fresher in your team encounters a ‘StaleElement’ exception while executing an automated test suite. How will you help them solve this issue?
There are two causes for this exception. Element in the web page that was a part of the current instance has been refreshed or navigated to another web page. This causes the element to be destroyed or reconstructed. The second reason is that the element is no longer attached to the DOM. These are the breakthroughs that I will provide my team members with to solve this issue:
//You can try refreshing the webpage using the navigate command.
driver. navigate().refresh()
driver.findElement (By.xpath(“sample”)).click();
//You can use a try-catch block within a for loop if the element is
// not attached to the DOM
for(int i=0;i<=2;i++)
{ try { driver.findElement(By.xpath("sample")).click();
break; }
Catch (Exception e){
Sysout(e.getMessage());
}
}
If you are sure that the element will be available, use the ExpectedConditions.refreshed method to avoid the StaleElementReference exception. This method updates the element by redrawing it and providing access to the referenced element
wait.until(ExpectedConditions.refreshed(ExpectedConditions.stalenessOf("sample")));
//ExpectedConditions class provide below method
stalenessOf(WebElement element)
//It means is as below
Wait until an element is no longer attached to the DOM
6. You have been asked to perform automation testing on a website that loads at a
slow pace. You can execute the scenario manually without any impediments other than the speed issue. But while automation, a NoSuchElementFound exception is thrown.Your test lead suggests making a change in the navigation commands. How will you handle this situation?
- From my observation of the test scripts, I find that the .navigate().to() method has been used, which is not advisable in this case.
- driver. get() commands are perfect for a website that loads slowly, waits for the page to get loaded fully, and proceeds to the next steps.
- However, while using driver.navigateto() method, the driver does not wait for the page to be loaded completely, and many components are loaded yet, which throws the NoSuchElement exception.
7. What is Stalelementexception
- The web element we are looking for is no longer attached to the dom
- It can be replaced with a new element
No comments:
Post a Comment