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?

1 Answer 1

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
    
Sign up to request clarification or add additional context in comments.

8 Comments

Doesn't seem to work: it still returns that error (by the way I had it implicitly waitin before clicking, will it still work?)
@Grinch Remove the implicit way totally. Mixing up both of them results in unpredictable waits.
But I also realized that <div class="market-selection ng-scope active"... is when it is clicked, otherwise it's <div class="market-selection ng-scope" ... but even changing the path it won't work
Even if I didn't have WebDriverWait? I only used implicitly wait
Ok it worked out, I didn't properly test your xpath solution AFTER removing "active". Thank you
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.