Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python Selenium, Error with find_element_by() command

I don't know the reason for this error, for some reason the find_element_by_() commands are not being recognized, I've already tried to reinstall everything, I changed the Python version, nothing works, does anyone know how to solve this problem?

Error: Unresolved attribute reference 'find_element_by_name' for class 'WebDriver

like image 225
BOB CÃOMUNISTA Avatar asked Jul 22 '26 13:07

BOB CÃOMUNISTA


2 Answers

find_element_by_* methods are now deprecated.
find_element(By. are used now.
So, instead of find_element_by_name it is a driver.find_element(By.NAME, "name_attribute") now.
Similarly driver.find_element(By.XPATH, "element_xpath_locator") etc.
To use these methods you will need the following import:

from selenium.webdriver.common.by import By
like image 97
Prophet Avatar answered Jul 24 '26 02:07

Prophet


Make sure you import By from selenium

from selenium.webdriver.common.by import By

then you would format your code like this

dv.find_elements(By.NAME,"<enter name value>")
like image 30
Rihhard Avatar answered Jul 24 '26 03:07

Rihhard



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!