简体   繁体   中英

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

Goal: Click by class name.

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>

Attempt:

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')

Screenshot of HTML

Element you are trying to locate here having multiple class names. Such element can be located by XPATH or CSS_SELECTOR while By.CLASS_NAME supports single class name only, so instead of

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')

you can use

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')

Please pay attention that locator you are using looks not too much reliable, you possibly could improve it.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM