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
E2: tried answer from pmadhu
Traceback (most recent call last):
File "C:/Users/KDK/Desktop/NOVY SEARCH AUTO/test2.py", line 9, in <module>
shadowroot.find_element_by_css_selector("#uc-center-container > div > div.sc-hiKfDv.gGhxCY > div > div.sc-ezzafa.bUHURR > div > button.sc-gtsrHT.ctrzIr").click()
File "C:\Users\KDK\anaconda3\lib\site-packages\selenium\webdriver\remote\webelement.py", line 430, in find_element_by_css_selector
return self.find_element(by=By.CSS_SELECTOR, value=css_selector)
File "C:\Users\KDK\anaconda3\lib\site-packages\selenium\webdriver\remote\webelement.py", line 658, in find_element
return self._execute(Command.FIND_CHILD_ELEMENT,
File "C:\Users\KDK\anaconda3\lib\site-packages\selenium\webdriver\remote\webelement.py", line 633, in _execute
return self._parent.execute(command, params)
File "C:\Users\KDK\anaconda3\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 321, in execute
self.error_handler.check_response(response)
File "C:\Users\KDK\anaconda3\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 242, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"css selector","selector":"#uc-center-container > div > div.sc-hiKfDv.gGhxCY > div > div.sc-ezzafa.bUHURR > div > button.sc-gtsrHT.ctrzIr"}