簡體   English   中英

EASY PYTHON SELENIUM:如何點擊 class 名稱?

[英]EASY PYTHON SELENIUM: How do I click by class name?

目標:按 class 名稱單擊。

HTML:

<span class="Icon-Svg Link-Icon-Svg next-Link-Icon-Svg Pagination-RightControl-Link-Icon-Svg Pagination-Page-Link-Icon-Svg" 

style="-webkit-mask-image: url(&quot;https://[REDACTED]/icon/ArrowRight.svg&quot;); -webkit-mask-size: contain; -webkit-mask-repeat: no-repeat; -webkit-mask-position: center center;"></span>

試圖:

driver.find_element(By.CLASS_NAME, 'Icon-Svg Link-Icon-Svg next-Link-Icon-Svg Pagination-RightControl-Link-Icon-Svg Pagination-Page-Link-Icon-Svg')

HTML截圖

您試圖在此處找到具有多個 class 名稱的元素。 此類元素可以通過 XPATH 或 CSS_SELECTOR 定位,而By.CLASS_NAME僅支持單個 class 名稱,因此而不是

driver.find_element(By.CLASS_NAME, 'Icon-Svg Link-Icon-Svg next-Link-Icon-Svg Pagination-RightControl-Link-Icon-Svg Pagination-Page-Link-Icon-Svg')

您可以使用

driver.find_element(By.CSS_SELECTOR, 'span.Icon-Svg.Link-Icon-Svg.next-Link-Icon-Svg.Pagination-RightControl-Link-Icon-Svg.Pagination-Page-Link-Icon-Svg')

請注意,您使用的定位器看起來不太可靠,您可以改進它。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM