AttributeError: 'WebDriver' object has no attribute 'find_element_by_xpath'


from selenium import webdriver
import time

test = webdriver.Chrome()
test.get('        d1zkmSaEHodJXs78RzoG0yFY2w/viewform')


Name = 'kuch bhi'
last = test.find_element_by_xpath('//*[@id="mG61Hd"]/div[2]/div/div[2]/div[1]/div/div/div[2]/div/div[1]/div/div[1]/input')

When i execute the code, I get an error that says,

AttributeError: ‘WebDriver’ object has no attribute ‘find_element_by_xpath’


Selenium just removed that method in version 4.3.0. See the CHANGES:

Selenium 4.3.0
* Deprecated find_element_by_* and find_elements_by_* are now removed (#10712)
* Deprecated Opera support has been removed (#10630)
* Fully upgraded from python 2x to 3.7 syntax and features (#10647)
* Added a devtools version fallback mechanism to look for an older version when mismatch occurs (#10749)
* Better support for co-operative multi inheritance by utilising super() throughout
* Improved type hints throughout

You now need to use:

driver.find_element("xpath", '//*[@id="mG61Hd"]/div[2]/div/div[2]/div[1]/div/div/div[2]/div/div[1]/div/div[1]/input')

In your example, you would use:

last = test.find_element("xpath", '//*[@id="mG61Hd"]/div[2]/div/div[2]/div[1]/div/div/div[2]/div/div[1]/div/div[1]/input')

For improved reliability, you should consider using WebDriverWait in combination with element_to_be_clickable.

Answered By – Michael Mintz

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published