Example –

Let’s demonstrate Exception by trying to find an element that doesn’t exist and click it at w3wiki.org 

Python3




# import webdriver
from selenium import webdriver
from selenium.webdriver.common.by import By
 
# create webdriver object
driver = webdriver.Firefox()
 
# get w3wiki.org
driver.get("https://www.w3wiki.org/")
 
# get element
element = driver.find_element(By.LINK_TEXT, "abrakadabra")
 
# click the item
print(element.click())


Now, let’s run this program, it first open w3wiki.org and then raise exception – selenium.common.exceptions.NoSuchElementException, which means that element doesn’t exist on the website. 

Exceptions – Selenium Python

Exceptions in Selenium Python are the errors that occur when one of method fails or an unexpected event occurs. All instances in Python must be instances of a class that derives from BaseException. Two exception classes that are not related via subclassing are never equivalent, even if they have the same name. The built-in exceptions can be generated by the interpreter or built-in functions. This article revolves around multiple exceptions that can occur during the run of a Selenium program.

Similar Reads

Example –

Let’s demonstrate Exception by trying to find an element that doesn’t exist and click it at geeksforgeeks.org...

Exceptions in Selenium Python

...