1

I'm trying to click an element on a web page using selenium and python

driver.find_element_by_class_name("market-selection.ng-scope").click()

But I get the error that the element isn't clickable

selenium.common.exceptions.ElementNotInteractableException: Message: element not interactable

This is the element html (it's not in a frame btw); I'm guessing that the interactable part is the second div but I also tried the other two just in case...

<div class="market-selection-container 18" ng-repeat="market in wrapperCategoryGroup.currentMacroCategoria.mkl track by $index">
      <!-- ngIf: wrapperCategoryGroup.marketTypes[market].nm    -->
      <div class="market-selection ng-scope" ng-if="wrapperCategoryGroup.marketTypes[market].nm" ng-class="{'active':wrapperCategoryGroup.currentMarketType == market}" ng-click="wrapperCategoryGroup.getMarketType(market)" style="">
        <span class="ng-binding">
          doppia chance 
        </span>
      </div>
    <!-- end ngIf: wrapperCategoryGroup.marketTypes[market].nm -->
 </div>

Any hint?

Grinch
  • 179
  • 1
  • 9

1 Answers1

1

To click on the element with text as save you can use either of the following Locator Strategies:

  • Using css_selector:

    driver.find_element_by_css_selector("div.market-selection.ng-scope > span.ng-binding").click()
    
  • Using xpath:

    driver.find_element_by_xpath("//div[@class='market-selection ng-scope']/span[@class='ng-binding' and contains(., 'doppia chance')]").click()
    

Ideally, to click on the element you need to induce WebDriverWait for the element_to_be_clickable() and you can use either of the following Locator Strategies:

  • Using CSS_SELECTOR:

    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "div.market-selection.ng-scope > span.ng-binding"))).click()
    
  • Using XPATH:

    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//div[@class='market-selection ng-scope']/span[@class='ng-binding' and contains(., 'doppia chance')]"))).click()
    
  • Note: You have to add the following imports :

    from selenium.webdriver.support.ui import WebDriverWait
    from selenium.webdriver.common.by import By
    from selenium.webdriver.support import expected_conditions as EC
    
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352