Junior — Middle
Can you name three examples of exceptions that may occur when working with Selenium?
sobes.tech AI
Answer from AI
Three common exceptions in Selenium:
-
NoSuchElementException — occurs when Selenium cannot find an element on the page using the specified locator.
-
TimeoutException — occurs if the wait (for example, via WebDriverWait) expires and the condition has not been met.
-
StaleElementReferenceException — happens when the element you are trying to interact with no longer exists in the DOM (for example, the page has been refreshed).
Example of handling an exception in Python:
from selenium.common.exceptions import NoSuchElementException
try:
element = driver.find_element_by_id('my-element')
except NoSuchElementException:
print('Element not found')