【发布时间】: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 do 和 selenium.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