简体   繁体   中英

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

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

my selenium version is 4.4.3. I have used 4.3.0 version code but, there is no use.

My code:

from selenium import webdriver
import time

username = ' ' # Change to your username here
password = ' ' # Change to your password here
url='https://academia.srmist.edu.in/'
driver = webdriver.Chrome("./chromedriver")
driver.get(url)
time.sleep(2)
driver.find_element_by_xpath('//*[@id="Email"]').send_keys(username)
driver.find_element_by_xpath('//*[@id="Password"]').send_keys(password)
time.sleep(1)
driver.find_element_by_xpath('//*[@id="signinForm"]/div[6]/input').click()

Selenium 4 has no more methods like find_element_by_xpath .
Use the following style instead:

driver.get(url)
time.sleep(2)
driver.find_element_by(By.XPATH, '//*[@id="Email"]').send_keys(username)
driver.find_element_by(By.XPATH, '//*[@id="Password"]').send_keys(password)
time.sleep(1)
driver.find_element(By.XPATH, '//*[@id="signinForm"]/div[6]/input').click()

The same with all other methods like find_element_by_css_selector , find_element_by_id etc.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM