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

Time:01-30

Goal: Click by class name.

HTML:

<span  

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

CodePudding user response:

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.

  •  Tags:  
  • Related