mercredi 4 août 2021

Selenium accept cookies python

I am trying to accept cookies on website, sadly I cannot refer to the "accept all" button. I have directly in the code time.sleep(10) so there should not be a problem with the wait on the popup/consent to be visible - which is something I mostly saw in similar threads.

driver.get("https://fischer.cz")
time.sleep(10)        
prijmoutVse = driver.find_element_by_xpath("//*[@class='sc-gtsrHT ctrzIr']")
driver.click(prijmoutVse)

I am getting selenium error that says it is unable to locate the element. I am unable to locate it with xpath helper in browser even when I copy the full xpath, all the results are null.

I tried driver.switch_to.alert as well but did not get this to working.

Tried following locators :

//*[@data-testid="uc-accept-all-button"]
/html/body/div[15]//section/div/div[2]/div[3]/div/div[1]/div/button[3]
//*[@id="uc-center-container"]/div[3]/div/div[1]/div/button[3]

code of the consent here is print of the element from console, I noticed there are some "flex" tags but not too sure what they mean or if it could cause trouble.

I am kinda desperate at this point since it blocks my work and I cant figure a way to work around it. I will be happy for any comments or thoughts how to solve that!

Thanks in advance

E1: tried the answer from cruisepandey getting this error

    Traceback (most recent call last):
  File "C:/Users/KDK/Desktop/NOVY SEARCH AUTO/test2.py", line 10, in <module>
    wait.until(EC.element_to_be_clickable((By.XPATH, "//button[@data-testid='uc-accept-all-button']"))).click()
  File "C:\Users\KDK\anaconda3\lib\site-packages\selenium\webdriver\support\wait.py", line 80, in until
    raise TimeoutException(message, screen, stacktrace)
selenium.common.exceptions.TimeoutException: Message: 


Process finished with exit code 1



Aucun commentaire:

Enregistrer un commentaire