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
from selenium.webdriver import ChromeOptions
options = ChromeOptions()
options.add_argument("--headless")
with webdriver.Chrome(options=options) as driver:
driver.get("https://www.youtube.com/ads/")
wait = WebDriverWait(driver, 5)
selector = By.CSS_SELECTOR, "button.glue-cookie-notification-bar__reject"
try:
wait.until(EC.element_to_be_clickable(selector)).click()
except Exception:
pass
selector = By.CSS_SELECTOR, 'a[data-g-cta-name="promote-your-channel"]'
wait.until(EC.element_to_be_clickable(selector)).click()