This code is supposed to click a button (accept the cookies) and then take a screenshot of the page. It takes the screenshot of the right element with the right height & width, but it does not click the button before doing it.
The cookie button im talking about is the one on “u.gg”: <button class=”fc-button fc-cta-consent fc-primary-button” role=”button” aria-label=”Consent” tabindex=”0″>
I also tried clicking the buttons by coordinates, but i couldnt find the right ones.
The main question is: How do I tell Python to click that button?
This image shows the button with the green Consent button i want to click()
enter image description here
Im also open to other solutions like cookieblockers.
from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.common.by import By
from selenium.webdriver.chrome.options import Options
import time
url = "https://u.gg/lol/champions/kayle/build"
options = Options()
options.add_argument("--headless")
options.add_argument("--start-maximized")
service = Service("chromedriver.exe")
driver = webdriver.Chrome(service=service, options=options)
try:
driver.get(url)
time.sleep(2)
button = driver.find_element(By.CSS_SELECTOR,"button.fc-button.fc-cta-consent.fc-primary-button[role='button'][aria-label='Consent']")
element = driver.find_element(By.CLASS_NAME,"champion-recommended-build")
button.click
time.sleep(2)
driver.execute_script("arguments[0].scrollIntoView();", element)
time.sleep(2)
screenshot_path = "uggscreenshot.png"
driver.save_screenshot(screenshot_path)
print(f"Screenshot saved to {screenshot_path}")
finally:
driver.quit()