我想在我的測驗頁面上使用 click 命令。但我收到以下錯誤。我用python寫的
from selenium import webdriver
from selenium.webdriver.common.action_chains import ActionChains
import time
import pandas as pd
url="https://tv.com/home"
options = webdriver.ChromeOptions()
options.binary_location ="C:\Program Files\Google\Chrome\Application\chrome.exe"
driver = webdriver.Chrome("chromedriver.exe",chrome_options=options)
driver.get(url
driver.maximize_window()
time.sleep(20)
arr=[]
driver.find_element_by_css_selector("._1DRQ8").click()
x=driver.find_element_by_css_selector("._1sZ9q").find_elements_by_tag_name("a")
獲取錯誤:
driver.find_element_by_css_selector("._1DRQ8").click()
AttributeError: 'dict' object has no attribute 'click'
uj5u.com熱心網友回復:
你的代碼沒有問題。可能您正在使用舊版本的ChromeDriver回傳錯誤形狀的物件。
解決方案
確保這件事:
- ChromeDriver更新到當前ChromeDriver v96.0級別。
- Chrome更新為當前的chrome=96.0.4664.45(根據chrome=96.0.4664.45 發行說明)。
tl; 博士
FIND_ELEMENT 命令回傳一個 dict 物件值
uj5u.com熱心網友回復:
也許您正試圖在元素準備好可點擊之前點擊它。
試試這個
from selenium.webdriver.support.ui import WebDriverWait
elem = WebDriverWait(driver, 30).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "._1DRQ8")))
elem.click()
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/378703.html
