Skip to content Skip to sidebar Skip to footer

Click On Ember.js Enabled Element Using Selenium

I am trying to click on the following button on a linkedin page using selenium:
  • Using xpath:

    driver.find_element_by_xpath("//button[contains(@class, 'share-actions__primary-action') and @data-control-name='share.post']/span[@class='artdeco-button__text' and contains(., 'Post')]").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, "button.share-actions__primary-action[data-control-name='share.post']>span.artdeco-button__text"))).click()
      
    • Using XPATH:

      WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//button[contains(@class, 'share-actions__primary-action') and @data-control-name='share.post']/span[contains(., 'Post')]"))).click()
      
    • Note: You have to add the following imports :

      from selenium.webdriver.support.uiimportWebDriverWaitfrom selenium.webdriver.common.byimportByfrom selenium.webdriver.supportimport expected_conditions asEC

    References

    You can find a couple of relevant detailed discussions in:

    Solution 2:

    Sometimes there are problems with buttons that are not clickable at the moment. Try this:

    from selenium.webdriver.support import expected_conditions as EC
    from selenium.webdriver.support.ui import WebDriverWait
    from selenium.webdriver.common.by import By
    
    
    wait = WebDriverWait(driver, 10)
    
    button = wait.until(EC.element_to_be_clickable((By.XPATH, '[YOUR X_PATH TO THE BUTTON]')))
    driver.execute_script("arguments[0].click()", button)
    

    It's not the cleanest way to click any Button with selenium, but for me this method works mostly everytime.

    Solution 3:

    //button[@class="share-actions__primary-action artdeco-button artdeco-button--2 artdeco-button--primary ember-view"]. 
    

    Or

    //button[contains(@id,'ember')]
    

    Solution 4:

    Find the span with Post and click it's button tag.

    //span[contains(text(), 'Post')]/parent::button
    

    Solution 5:

    By xpath this should work:

    //button/span[contains(text(), "Post")]

    Combine it with a wait for the element:

    button = WebDriverWait(driver, 10).until(
            EC.element_to_be_clickable((By.XPATH, "//button/span[contains(text(), "Post")]"))
        )
    

    The problem with your by class selectors is the multiple class names. See this question: How to get elements with multiple classes for more details on how to overcome that.

    Post a Comment for "Click On Ember.js Enabled Element Using Selenium"