I am trying to parse this website using selenium but I fail to find the buttons of the cookie popup which I need to confirm to proceed. I know that I first need to load the page and then wait for the cookie popup to appear, although that should be well handled by the sleep function.
The html of the buttons inside the popup looks like this (retrieved via firefox F12). I am trying to simply click the "OK" button:
<button role="button" data-testid="uc-customize-button" style="border: 1px solid rgb(0, 139, 2);" class="sc-gsDKAQ hWcdhQ">Einstellungen oder ablehnen</button>
<div class="sc-bBHxTw foBPAO"></div>
<button role="button" data-testid="uc-accept-all-button" style="border: 1px solid rgb(0, 139, 2);" class="sc-gsDKAQ fILFKg">OK</button>
I have tried to simply find the buttons via the xpath of the "OK" button:
from time import sleep
from selenium import webdriver
from selenium.webdriver.common.by import By
# adapting: https://stackoverflow.com/questions/64032271/handling-accept-cookies-popup-with-selenium-in-python
BASE_URL = "https://www.immowelt.at/suche/wohnungen/mieten"
driver = webdriver.Firefox()
driver.get(BASE_URL)
sleep(10)
# cannot locate by XPATH
driver.find_element(
By.XPATH, "/div/div/div[2]/div/div[2]/div/div/div/button[2]"
).click()
# weird thing is, I also cannot retrieve any of the buttons (although I know they exist)
buttons = driver.find_elements(By.TAG_NAME, "button")
Any ideas why I can't find the button?