from selenium import webdriver driver = webdriver.Chrome(executable_path=r'C:\webdrivers\chromedriver.exe') driver.get('https://www.youtube.com') while True: try: skip= driver.find_element_by_class_name('ytp-ad-skip-button-container') skip.click() except: continue