How to select in selenium

Viewed 23

I want to click this button in a website using selenium but I am not sure how to select it.

<a data-gfm-analytics-element="btn_showmore_browse" data-area="norma_category" class="button hollow expanded-mobile js-load-more-results" href="#" style="display: inline-block;">Show More</a> 

I used this code to do it but it returns NoSuchElementException: Message: no such element

btn = driver.find_element(By.CLASS_NAME,'button hollow expanded-mobile js-load-more-results')
1 Answers

button hollow expanded-mobile js-load-more-results are actually 4 class names while By.CLASS_NAME receives single class name value. You can use CSS Selector or Xpath with multiple class names

btn = driver.find_element(By.CSS_SELECTOR,'a.button.hollow.expanded-mobile.js-load-more-results')

Also btn_showmore_browse seems to be unique value, so possibly this will work too:

btn = driver.find_element(By.CSS_SELECTOR,'a[data-gfm-analytics-element="btn_showmore_browse"]')

There are more possible options

Related