亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

Selenium 不會加載鏈接文本 - 我錯過了什么

Selenium 不會加載鏈接文本 - 我錯過了什么

浮云間 2023-10-26 10:27:25
嘗試讓 Selenium 在訪問注冊表單之前單擊 cookie 策略按鈕上的“接受”。(我想自動化等候名單功能,因為這在這個健身房總是一場競賽)但我陷入了第一個障礙,并花了幾個小時試圖破譯錯誤消息。你能幫忙嗎?代碼import seleniumfrom selenium import webdriverfrom selenium.webdriver.common.keys import KeysPATH = "C:\Program Files (x86)\chromedriver.exe"driver = webdriver.Chrome(PATH)driver.get("https://member.superfit.club/")driver.find_element_by_link_text("Akzeptieren").click()錯誤信息:Traceback (most recent call last):  File "C:\Users\Csongor\Dropbox\Coding\new test 6th oct 2020\test.py", line 8, in <module>    driver.get("https://member.superfit.club/").find_element_by_link_text("Akzeptieren").click()AttributeError: 'NoneType' object has no attribute 'find_element_by_link_text'
查看完整描述

4 回答

?
慕勒3428872

TA貢獻1848條經驗 獲得超6個贊

您可以通過文本值找到該按鈕。


試試這個代碼:


import selenium

from selenium import webdriver

from selenium.webdriver.common.keys import Keys


PATH = "C:\Program Files (x86)\chromedriver.exe"

driver = webdriver.Chrome(PATH)


driver.get("https://member.superfit.club/")


#driver.find_element_by_link_text("Akzeptieren").click()

driver.find_element_by_xpath('//button[contains(text(), "Akzeptieren")]').click()


查看完整回答
反對 回復 2023-10-26
?
尚方寶劍之說

TA貢獻1788條經驗 獲得超4個贊

你為什么不直接使用xpath而不是link text?

driver.find_element_by_xpath('//*[@id="CookieModelButtom"]/div/div/div/div/button[1]').click()

這工作得很好。我建議您使用xpathsorCSS Selectors代替Link Texts。


查看完整回答
反對 回復 2023-10-26
?
慕尼黑的夜晚無繁華

TA貢獻1864條經驗 獲得超6個贊

您顯示的代碼不反映錯誤堆棧跟蹤中的內容。顯然,你是find_element_by_link_text這樣調用的:


driver.get("https://member.superfit.club/").find_element_by_link_text("Akzeptieren").click()

當你應該像你自己展示的那樣做時:


driver.get("https://member.superfit.club/")

driver.find_element_by_link_text("Akzeptieren").click()


查看完整回答
反對 回復 2023-10-26
?
當年話下

TA貢獻1890條經驗 獲得超9個贊

find_element_by_link_text() 適用于錨元素而不是按鈕元素。您與之交互的元素是按鈕,因此您可以識別 ID、NAME、XPATH 或 CSS 選擇器。


我建議你使用WebDriverWait()and element_to_be_clickable() 和下面的 css 選擇器。


WebDriverWait(driver,10).until(EC.element_to_be_clickable((By.CSS_SELECTOR,"button.btn.btn-success"))).click()

您需要導入以下庫。


from selenium.webdriver.support.ui import WebDriverWait

from selenium.webdriver.common.by import By

from selenium.webdriver.support import expected_conditions as EC


查看完整回答
反對 回復 2023-10-26
  • 4 回答
  • 0 關注
  • 225 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號