0

I'm making some test with selenium on this page: https://www.justwatch.com/es/proveedor/hbo-max/peliculas

The first time you get in the page you must accept the privacy settings but I cannot get it to work. I've tried all the methods I now but it seems like I can't find the button I want so the program stops as the waiting time ends. The button I want to click is:

<button role="button" data-testid="uc-save-button" class="sc-gsDKAQ eaUldE" style="margin: 0px 6px;">Guardar configuración</button>

I tried to locate the button by text, class and using the XPath but doesnt work.

WebDriverWait(driver, 5)\
.until(EC.element_to_be_clickable((By.CLASS_NAME, 'sc-gsDKAQ eaUldE'.replace(' ', '.'))))\
.click()

WebDriverWait(driver, 5)\
.until(EC.element_to_be_clickable((By.XPATH, '/html/body/div[2]//div/div/div/div/div[2]/div/div[2]/div/div/div/button[1]')))\
.click()

WebDriverWait(driver, 5)\
.until(EC.element_to_be_clickable((By.LINK_TEXT, 'Guardar configuración')))\
.click()

I will appreciate your help.

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459

1 Answers1

0

To click on the desired element 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[data-testid='uc-save-button']"))).click()
    
  • Using XPATH:

    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//button[@data-testid='uc-save-button' and text()='Guardar configuración']"))).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
  • thanks for you answer but it didnt work. I tryed clicking on other elements of the page and it works, i think the problem may be caused by the button being on privacy settings pop up. Do you know if it may have anything to do with the issue – este_pais Jul 26 '22 at 17:05