0

I have an update button and in python, bot ı want to click this button but ı try many options but not working ı can't locate element by XPath. Please help me? Thanks for your help.

Note: I need to locate by using the text "Update" because a lot of buttons ı have on a webpage.

<span class="a-spacing-top-small">
  <span class="a-button a-button-primary a-button-small sc-update-link" id="a-autoid-2">
    <span class="a-button-inner">
      <a href="javascript:void(0);" data-action="update" class="a-button-text" role="button" id="a-autoid-2-announce" style="">Update
        <span class="aok-offscreen">Nike Academy 18 Rain Jacket Men's (Obsidian, M)</span>
      </a>
    </span>
  </span>
</span>

1
  • 3
    can you update the question with the code trial and error you facing Commented Feb 26, 2020 at 8:57

2 Answers 2

2

This should work:

button = driver.find_element_by_xpath("//a[@data-action,'update']")

Where driver is your instance of driver.

Sign up to request clarification or add additional context in comments.

Comments

1

The desired element is a JavaScript enabled element so to locate/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, "span.a-button.a-button-primary.a-button-small.sc-update-link[id^='a-autoid'] a.a-button-text[id$='announce']>span.aok-offscreen"))).click()
    
  • Using XPATH:

    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//span[@class='a-button a-button-primary a-button-small sc-update-link' and starts-with(@id,'a-autoid')]//a[@class='a-button-text' and contains(@id,'announce')]/span[@class='aok-offscreen' and starts-with(., 'Nike Academy 18 Rain Jacket Men')]"))).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
    

Comments

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.