-1

HTML CODE

I tried this method that works perfectly for other buttons (different class) on the same web page but not this specific button, I also tried using div class:

xpathoo = '//button[@class="ncss-brand pt2-sm pr5-sm pb2-sm pl5-sm ncss-btn-accent continueOrderReviewBtn mod-button-width ncss-brand\
        pt3-sm prl5-sm pb3-sm pt2-lg pb2-lg d-sm-b d-md-ib u-uppercase u-rounded fs14-sm"]' 
driver.find_element_by_xpath(xpathoo).click()
JeffC
  • 22,180
  • 5
  • 32
  • 55
Dip
  • 11
  • 2
  • 1
    that class value seems that may change(when you resize the screen for example), what if you use the value of data-attr? something like `//button[@data-attr='continueToOrderReviewBtn']` – Yacdaniel Hurtado Jan 03 '20 at 19:35

1 Answers1

0

The element with text as PASSA ALLA VERIFICA DELL is a dynamic element so click on it you have 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.continueOrderReviewBtn[data-attr='continueToOrderReviewBtn']"))).click()
    
  • Using XPATH:

    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//button[@data-attr='continueToOrderReviewBtn' and contains(., 'PASSA ALLA VERIFICA DELL')]"))).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