exception selenium code example
Example 1: exceptions in selenium
-> NoSuchElementException:
Once I get this exception I usually check
or
or
----> StaleElementException (reference not fresh anymore)
- We need to refresh the reference of the web element throwing this exception.
- Page Object Design pattern solves this problem.
- POM Design pattern will do something called a "freshness" check for
the web element being used.
- What is freshness check: re-locating web element with given locator
everytime we use.
---> TimeOutException
-I get this exception only when you use explicit wait (WebDriverWait)
-If explicit condition (element to be clickable) is not met, selenium
will throw this exception.
-> ElementNotVisible
-> ElementNotInteractable
-> ElementNotClickable
Example 2: exception selenium
-> NoSuchElementException:
Once I get this exception I usually check
----> StaleElementException (reference not fresh anymore)
- We need to refresh the reference of the web element throwing this exception.
- Page Object Design pattern solves this problem.
- POM Design pattern will do something called a "freshness" check for
the web element being used.
- What is freshness check: re-locating web element with given locator
everytime we use.
---> TimeOutException
-I get this exception only when you use explicit wait (WebDriverWait)
-If explicit condition (element to be clickable) is not met, selenium
will throw this exception.
-> ElementNotVisible
-> ElementNotInteractable
-> ElementNotClickable
Example 3: how do you handle exceptions in selenium
I use try & catch & finally block
to handle exception if I will use the method
in different class.
Or If I will use it only once and if it is checked
exception then I use THROWS keyword on method signature