Recently, I was trying to use the method “find_elements_by_xpath’ but continuously I am seeing the below error in Python:
AttributeError: ‘WebDriver’ object has no attribute ‘find_elements_by_xpath’
I would discuss in detail that how I was able to solve the AttributeError: ‘WebDriver’ object has no attribute ‘find_elements_by_xpath’ in Python.
Why AttributeError: ‘WebDriver’ object has no attribute ‘find_elements_by_xpath’ Occurred?
Error is seen because recently Selenium has released the latest 4.3.0
version and depreciated the commands find_element_by_* and find_elements_by_*. You can read the Selenium Official documentation Here.
So as per Selenium official announcement, they have released the latest version 4.3.0
and removed the support for below commands:
find_element_by_*
find_elements_by_*
How to Solve AttributeError: ‘WebDriver’ object has no attribute ‘find_elements_by_xpath’?
To fix error, use the find_element instead of ‘find_elements_by_xpath’ command. It would solve the AttributeError: ‘WebDriver’ object has no attribute ‘find_elements_by_xpath’ Error.
As Selenium has recently depreciated the commands find_element_by_* and find_elements_by_*, To solve the error, instead use the command, find_element. It would solve the AttributeError: ‘WebDriver’ object has no attribute ‘find_elements_by_xpath’. Below is the Selenium official update for find_element_by_* and find_elements_by_* commands removal:
Selenium 4.3.0 * Deprecated find_element_by_* and find_elements_by_* are now removed (#10712)
Use the below step by step process to solve the AttributeError: ‘WebDriver’ object has no attribute ‘find_elements_by_xpath’ Error.
Fix 1: Use the find_element Instead
To solve the issue, use the below command
find_element
Instead of find_element_by_* and find_elements_by_* commands.
Once you use the command find_element, it would solve the AttributeError: ‘WebDriver’ object has no attribute ‘find_elements_by_xpath’.
Below is the format, how to use the find_element command, to solve the AttributeError: ‘WebDriver’ object has no attribute ‘find_elements_by_xpath’:
driver.find_element("name", "q")
Conclusion
To Fix the error, Use the command find_element instead of find_element_by_name command. It would solve the AttributeError: ‘WebDriver’ object has no attribute ‘find_elements_by_xpath’ Error.