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>
DebanjanB
  • 118,661
  • 30
  • 168
  • 217

2 Answers2

2

This should work:

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

Where driver is your instance of driver.

OceanFire
  • 294
  • 2
  • 8
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
    
DebanjanB
  • 118,661
  • 30
  • 168
  • 217