WebDriver object has no attribute ‘find_element_by_xpath‘解决方法

内容纲要

好久没用selenium,最新由于需求重新上手之前跑的正常程序

结果报错:’WebDriver’ object has no attribute ‘find_element_by_xpath’

file

经一番debug之后,发现

selenium更新版本了,

之前的写法:

wd.find_element_by_xpath('/html/body/div[3]/div[2]/div/div[1]/div[1]/div[1]/div/ul/li[2]/a')

现在的写法:

wd.find_element(By.XPATH, '/html/body/div[3]/div[2]/div/div[1]/div[1]/div[1]/div/ul/li[2]/a')

记得导入包

from selenium.webdriver.common.by import By

成功!

标签

发表评论