AttributeError: ‘WebDriver’ object has no attribute ‘find_element_by_name’
The selenium “AttributeError: ‘WebDriver’ object has no attribute ‘find_element_by_name’” occurs because the find_element_by_name
method has been deprecated and removed starting Selenium 4.3.0.
Down grade your selenium version to 3.141.0 or just simply change the method to find_element
Locate the locators — Python bindings change upcoming
Updating the locators for changes in the Python bindings in selenium 4.
In Python Selenium 4.2 , the bindings will remove locator- specific methods for finding elements. This means that the methods
driver.find_element_by_id("some_id")
driver.find_element_by_name("some_name")
driver.find_element_by_tag_name("some_tag")
driver.find_element_by_css_selector("some_selector")
driver.find_element_by_class_name("some_class")
driver.find_element_by_link_text("some_text")
driver.find_element_by_partial_link_text("some_other_text")
driver.find_element_by_xpath("some_xpath")
will be removed, then will use the method as below
driver.find_element(By_object, "some_locator")
Here is an example of how to use the find_element
method instead of find_element_by_name
.
Code for Selenium 3, which still use locator-specific method
Code for Selenium 4, after changing the method by using By
To sum up, “AttributeError: ‘WebDriver’ object has no attribute ‘find_element_by_name’” occurs because the find_element_by_name
method has been deprecated and removed starting Selenium 4.3.0.
to solved that problem, use the find_element
method instead or downgrade the selenium version to 3.141.0