I am making a Python 3 script with Selenium 4 and Firefox Gecko web driver.
The goal is simple:
- Open a webpage
- Click on the blue "Greit"-button for accepting cookies
This is my Python 3 script so far, but it does not work as intended. The script does not seem to find the button. Perhaps because it is not part of the initial DOM. It is triggered by a javascript popup.
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as ec
import time
URL = 'https://examplepage.com'
driver = webdriver.Firefox()
driver.get(URL)
time.sleep(2)
print(driver.page_source)
wait = WebDriverWait(driver, 5)
wait.until(ec.visibility_of_element_located((By.XPATH, '//button[text()="Greit"]')))
driver.find_element(By.XPATH, '//button[text()="Greit"]').click()
driver.quit()
What can I do to make selenium find the button and click on it? The HTML for the popup is available in DevTools inspection, but not in the page source.
