0

I can't not make my python script click the consent cookie button on the page https://www.topparrain.com/de/users/sign_up

here is my code

from selenium import webdriver

firefox_options = webdriver.FirefoxOptions()
driver = webdriver.Remote(
    command_executor='http://localhost:4444',
    options=firefox_options
)
driver.maximize_window()
driver.get("https://www.topparrain.com/en/referral_codes")
driver.implicitly_wait(10000)
driver.find_element_by_xpath("//p[contains(text(),'Consent')]").click()
driver.implicitly_wait(3)
driver.quit()

I have tried Xpath and waiting but it doesn't click on it even I run the official docker selenium Firefox container

enter image description here

the HTML for the button is

<button class="fc-button fc-cta-consent fc-primary-button" role="button" aria-label="Consent" tabindex="0">
   <div class="fc-button-background"></div>
   <p class="fc-button-label">Consent</p>
</button>
RF1991
  • 2,037
  • 4
  • 8
  • 17

1 Answers1

0

I don't get the cookie consent popup accessing the url from APAC region.

However given the HTML:

cookie

To click on the element Consent 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.fc-button.fc-cta-consent.fc-primary-button[aria-label='Consent'] p"))).click()
    
  • Using XPATH:

    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//button[@class='fc-button fc-cta-consent fc-primary-button' and @aria-label='Consent']//p[text()='Consent']"))).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
  • 1
    thank you very much, this works. Could you explain to me what i did wrong ? i waited and i found the "p" class. – Kesch Johannsen Jul 21 '23 at 14:15
  • @KeschJohannsen Apprently your attempt doesn't looks wrong. However amidst a lot other things, first you need to ensure that `//p[contains(text(),'Consent')]` identifies the element uniquely. – undetected Selenium Jul 21 '23 at 18:57