AttributeError:“WebDriver”对象没有属性“find_element_by_xpath”错误

问题描述 投票:0回答:1

验证码:

try:
    driver.find_element_by_xpath(
        '/html/body/div[3]/div[1]/div[3]/div/div[4]/div/button'
    ).click()
except (
    common.exceptions.NoSuchElementException,
    common.exceptions.ElementClickInterceptedException
):
    continue
driver.set_window_position(-10000, 0)
print('[!] Running...')
captcha = False

我的错误:

enter image description here

这是我的代码,我已经尝试解决该错误几个小时了,但我所做的一切仍然会导致该错误,任何人都可以帮助我吗?

我尝试更改前缀,但什么也没做

selenium-webdriver webdriver
1个回答
0
投票

请检查你的selenium版本,这不是selenium4.1中正确的表达方式......

在 selenium 版本 4 中......正确的方法是:

driver.find_element(By.XPATH, '/html/body/div[3]/div[1]/div[3]/div/div[4]/div/button').click()

在版本 3 中...可以使用

driver.find_element_by_xpath
但版本 4...则不能

另外,请注意 iframe。

© www.soinside.com 2019 - 2024. All rights reserved.