我一直在努力解決 find_element_by_class_name 問題。我正在嘗試使用 selenium 和 chromedriver 登錄網頁。為此,我必須首先找到登錄按鈕并單擊它。不幸的是,當我使用 find_element_by_class_name 或 find_element_by_xpath 方法時,我收到以下錯誤消息:selenium.common.exceptions.NoSuchElementException:消息:沒有這樣的元素:無法定位元素我使用的是硒版本 3.141.0鉻版本 86.0.4240.75蟒蛇3這是我的代碼:import osfrom selenium import webdriverfrom selenium.webdriver.common.keys import Keysfrom selenium.webdriver.common.by import Byfrom selenium.webdriver.support.ui import WebDriverWait# Load driver (for Google Chrome) chromedriver = "/usr/local/bin/chromedriver"os.environ["webdriver.chrome.driver"] = chromedriverdriver = webdriver.Chrome(chromedriver)url = "https://bib.cnrs.fr/#"driver.get(url)# Authentificationdriver.implicitly_wait(10)connexion = driver.find_element_by_class_name("login-button.btn.btn-link").click()我嘗試按照此處的建議等待頁面加載:selenium.common.exceptions.NoSuchElementException:消息:沒有這樣的元素:無法定位元素:我應該做什么和selenium.common.exceptions.NoSuchElementException:消息:無法定位元素:我還嘗試過使用此處建議的 xpath 方法:Troublefindingelement in Selenium with Python但無濟于事。盡管 html 源代碼中存在“login-button.btn.btn-linky”類,但該函數似乎找不到它。任何幫助將不勝感激。
1 回答

滄海一幻覺
TA貢獻1824條經驗 獲得超5個贊
問題是我有 2 個版本的 chromedriver,第一個對應于我擁有的早期版本的 chrome,第二個對應于我的新 chrome 版本 86.0.4240.75
看來硒默認調用舊版本??梢詮慕K端輸出的錯誤信息中查看正在使用的chromedriver版本。
我卸載了 chromedriver(兩個版本),并通過在此處獲取正確的軟件包(與我的 google-chrome 對應的軟件包)重新安裝了正確的版本: https: //chromedriver.chromium.org/downloads
添加回答
舉報
0/150
提交
取消