- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
What are the various important exceptions in Selenium?
The various important exceptions in Selenium are listed below −
TimeOutException − This exception is thrown if an action does not complete in a particular duration. If the page element does not load even after the waits.
driver.manage().timeouts().implicitlyWait(15,TimeUnit.SECONDS) ; driver.get(“https://www.tutorialspoint.com/index.htm” );
In the above program, an implicit wait of 15 seconds is added. If the page https://www.tutorialspoint.com/index.htm doesn’t load in 15 seconds, then TimeoutException will be thrown.
NoSuchElementException − This exception happens if the web element with particular attributes does not exist on the page. This exception class is a subclass of NotFoundException and is thrown if the driver is not successful in locating the elements.
driver.findElement(By.name("tutorial-test")).click(); //Exception Handling: try { driver.findElement(By.name("tutorial-test")).click(); } catch (NoSuchElementException e)
ElementNotVisibleException − This exception happens if the web element is not visible but it is present in DOM. It is a subclass of ElementNotInteractable class. In the scenarios when the driver tries to perform an action on an element which is not visible or hidden, this exception is thrown. Here, this exception happens if the element with attribute name tutorial-test is hidden.
driver.findElement(By.name("tutorial-test")).click(); //Exception Handling: try { driver.findElement(By.name("tutorial-test")).click(); } catch (ElementNotVisibleException e)
StaleElementException - This exception happens if the web element is not present because it either got deleted or not attached with DOM anymore. There is a minor difference with this exception from ElementNotVisibleException.
In a few incidents, it happens that a specific web element was created on the page without any issues, however currently it is absent may be because of DOM refresh, a new navigation page got added or switching to frame or window.
- Related Articles
- What are the various Components of Selenium?
- What are the various locators that Selenium supports?
- What are the various waits available in Selenium with python?
- What are the various methods available under Select class in Selenium?
- What are the custom exceptions in C#?
- What are checked exceptions in Java?
- What are unchecked exceptions in Java?
- What are custom exceptions in Java?
- What are chained exceptions in Java?
- Describe some of the exceptions available in Selenium with python?
- What are number format exceptions in Java?
- What are user-defined exceptions in C#?
- Selenium WebDriver- Revisiting Important Features
- What are the various Smartphone Sensors?
- Write some important uses of the various constituents of petroleum.
