【问题标题】:chromedriver selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate elementchromedriver selenium.common.exceptions.NoSuchElementException:消息:没有这样的元素:无法找到元素
【发布时间】:2020-10-29 08:36:02
【问题描述】:

我一直在为 find_element_by_class_name 苦苦挣扎。我正在尝试使用 selenium 和 chromedriver 登录网页。为此,我必须首先找到登录按钮并单击它。不幸的是,当我使用 find_element_by_class_name 或 find_element_by_xpath 方法时,我收到以下错误消息: selenium.common.exceptions.NoSuchElementException:消息:没有这样的元素:无法找到元素

我正在使用 selenium 版本 3.141.0

chrome 版本 86.0.4240.75

python3

这是我的代码:

import os
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait



# Load driver (for Google Chrome)  
chromedriver = "/usr/local/bin/chromedriver"
os.environ["webdriver.chrome.driver"] = chromedriver
driver = webdriver.Chrome(chromedriver)

url = "https://bib.cnrs.fr/#"


driver.get(url)

# Authentification
driver.implicitly_wait(10)
connexion = driver.find_element_by_class_name("login-button.btn.btn-link").click()

我已尝试按照此处的建议等待页面加载:selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element : what should i doselenium.common.exceptions.NoSuchElementException: Message: Unable to locate element:

我也尝试过这里建议的 xpath 方法:Trouble finding element in Selenium with Python 但无济于事。

尽管 html 源代码中存在“login-button.btn.btn-linky”类,但该函数似乎找不到它。

任何帮助将不胜感激。

【问题讨论】:

  • 页面链接在哪里?
  • 在变量“url”中
  • 按钮类名拼写错误。这是link 不是linky
  • 这个xpath 也适用于//button[normalize-space()='Sign in']
  • 感谢 cmets。不幸的是,这些更改对我不起作用

标签: python selenium selenium-chromedriver


【解决方案1】:

问题是我有 2 个版本的 chromedriver,第一个对应于我拥有的早期版本的 chrome,第二个对应于我的新 chrome 版本 86.0.4240.75

似乎 selenium 默认调用旧版本。可以在终端输出的错误信息中查看当前使用的是哪个版本的chromedriver。

我卸载了 chromedriver(两个版本)并通过在此处获取正确的软件包(与我的 google-chrome 对应的软件包)重新安装了正确的:https://chromedriver.chromium.org/downloads

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-12-20
    • 1970-01-01
    • 2021-01-25
    • 2019-10-25
    • 2021-11-05
    相关资源
    最近更新 更多