So, I'm trying to create a Script that opens a Google Chrome page and search "LMFAO", for example. Only a problem: Cookies. I want to learn how to delete a specific element from a webpage, in this case the Cookies Pop-up of youtube.
Here's the actual script.
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
import time
driver = webdriver.Chrome()
driver.get('https://youtube.com')
time.sleep(8)
driver.execute_script("""
const ll = document.getElementById("dialog")[0];
ll.remove();
""")
searchbox = driver.find_elements_by_xpath('//*[@id="search"]')
searchbox.send_keys('LMFAO')
Cookie Popup snapshot:
For the undetected Selenium Comment, here's the button html:
<tp-yt-paper-button id="button" class="style-scope ytd-button-renderer style-primary size-default" role="button" tabindex="0" animated="" elevation="0" aria-disabled="false" aria-label="Agree to the use of cookies and other data for the purposes described"><!--css-build:shady--><yt-formatted-string id="text" class="style-scope ytd-button-renderer style-primary size-default">I Agree</yt-formatted-string><paper-ripple class="style-scope tp-yt-paper-button"><!--css-build:shady-->
<div id="background" class="style-scope paper-ripple"></div>
<div id="waves" class="style-scope paper-ripple"></div>
</paper-ripple></tp-yt-paper-button>