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

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

有什么辦法可以點擊同一個圖標嗎?

有什么辦法可以點擊同一個圖標嗎?

胡子哥哥 2023-10-06 11:10:38
我想從頁面中單擊“進行中的球門線”下的所有矩形圖標(圖標看起來像足球場)。我嘗試了很多次但沒有成功。如果有人知道如何單擊這些所有圖標,請幫助我。from time import sleepfrom selenium import webdriverfrom selenium.webdriver.chrome.options import Optionschrome_options = Options()# chrome_options.add_argument("--headless")chrome_options.add_argument('--start-maximized')driver = webdriver.Chrome(options=chrome_options, executable_path=r"chromedriver.exe")driver.execute_cdp_cmd("Page.addScriptToEvaluateOnNewDocument", {"source": """Object.defineProperty(navigator, 'webdriver', {get: () => undefined})"""})url = 'https://www.bet365.com/#/IP/B1'driver.get(url)sleep(10)res = driver.execute_script("return document.documentElement.outerHTML")sleep(10)click_icon = driver.find_element_by_css_selector(".ovm-MediaIconContainer_Buttons div")click_icon.click()
查看完整描述

1 回答

?
aluckdog

TA貢獻1847條經驗 獲得超7個贊

(移動評論來回答)

兩個問題:

  • 您正在使用 搜索類和標簽find_element_by_css_selector。將此更改為僅搜索類名。

  • 要返回元素集合,請使用find_elements_by_css_selectorit 返回元素列表。

替換這段代碼:

click_icon = driver.find_element_by_css_selector(".ovm-MediaIconContainer_Buttons div")
click_icon.click()

有了這個:

icon_list = driver.find_elements_by_css_selector(".ovm-MediaIconContainer_Buttons")
for icon in icon_list:  # every icon in list
    icon.click()  # click single icon


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

添加回答

舉報

0/150
提交
取消
微信客服

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

幫助反饋 APP下載

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

公眾號

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