I'm trying to clear my chrome cookies, but i can't click a button: BUTTON
import os
import time
from selenium.webdriver.chrome.options import Options
from selenium import webdriver
opt = Options()
opt.add_argument("start-maximized")
executable_path = r'chromedriver'
os.environ["webdriver.chrome.driver"] = executable_path
global driver
driver = webdriver.Chrome(r'C:\Users\SAMSUNG\Desktop\chromedriver', options=opt)
driver.get("https://www.youtube.com")
driver.get("chrome://settings/clearBrowserData")
time.sleep(2)
driver.find_element_by_css_selector('#clearBrowsingDataConfirm').click()
The problem comes form the chained shadowroots that doesn't allow for the element to be found:
driver.get("https://www.youtube.com")
driver.get("chrome://settings/clearBrowserData")
time.sleep(5)
javaScript = "document.querySelector('settings-ui').shadowRoot.querySelector('settings-main').shadowRoot.querySelector('settings-basic-page').shadowRoot.querySelector('settings-section > settings-privacy-page').shadowRoot.querySelector('settings-clear-browsing-data-dialog').shadowRoot.querySelector('#clearBrowsingDataDialog').querySelector('#clearBrowsingDataConfirm').click()"
driver.execute_script(javaScript)
Related
I need to open web whatsapp but it gives me Deprecation Warning
here is the code
import selenium
from selenium import webdriver
import time
driver_path = r"C:\Program Files (x86)\Google\Chrome\Application\chrome.exe"
driver = webdriver.Chrome(driver_path)
driver.get("https://web.whatsapp.com/")
driver.maximize_window()
time.sleep(20)
driver.quit
İts not giving me anything just opens Chrome
DeprecationWarning: executable_path has been deprecated, please pass in a Service object
First you need download chromedriver - https://chromedriver.chromium.org/downloads
from selenium import webdriver
from selenium.webdriver.chrome.service import Service
import time
ser = Service('path_to\chromedriver.exe')
browser = webdriver.Chrome(service=ser)
browser.get('https://web.whatsapp.com/')
browser.maximize_window()
time.sleep(20)
browser.quit
You need to pass The driver_path to Service(). below should work for you.
from selenium import webdriver
from selenium.webdriver.chrome.service import Service
driver_path = r"chromdriver.exe full file path here"
service = Service(driver_path)
option = webdriver.ChromeOptions()
driver = webdriver.Chrome(service = service, options = option )
driver.get("https://web.whatsapp.com/")
driver.maximize_window()
time.sleep(20)
driver.quit
I am sucesfully able to load my chrome profile using the flags:
user-data-dir as well as profile-directory, yet once the profile is loaded and the chrome window is actually open, no webpage appears. It simply gets stuck on a blank screen.
When I remove the code for the profile it is actually able to open the webpage stored in the login-url variable.
Tried updating to latest version of chrome (94.0.4606.81) and I also used the exact steps listed here to ensure I have the right chrome driver version.
I also did the obvious like making sure there are not any instances of chrome running in the background.
Code is as follows:
import os
from os.path import exists
import selenium
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
headless = False
login_url = "https://google.com)"
def startChrome():
global headless
try:
chrome_options = Options()
if headless:
chrome_options.add_argument("--headless")
chrome_options.add_argument("----user-data-dir=C:/Users/ERIK/AppData/Local/Google/Chrome/User Data")
chrome_options.add_argument("--profile-directory=Profile 1")
global driver
driver = webdriver.Chrome(path+"/chromedriver.exe", options=chrome_options)
except:
print("Failed to start Chrome!")
input()
exit()
startChrome()
driver.get(login_url)
input()
The following successfully opens google.com for me.
Selenium Version 3.141.0
ChromeDriver Version 94.0.4606.61
Chrome Version 94.0.4606.71
from os import path
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
def getDriver(profile_directory, headless = False):
chrome_options = Options()
if headless:
chrome_options.add_argument("--headless")
userDataDir = path.expandvars(r"%LOCALAPPDATA%\Google\Chrome\User Data")
chrome_options.add_argument(f"--user-data-dir={userDataDir}")
chrome_options.add_argument(f"--profile-directory={profile_directory}")
return webdriver.Chrome("./chromedriver.exe", options=chrome_options)
driver = getDriver("Profile 2")
driver.get("https://google.com")
I have a code for making temp mail automatically but I have a problem.
This is code:
import time
from selenium import webdriver
browser = webdriver.Chrome()
browser.get("https://temp-mail.org/")
time.sleep(10)
browser.close()
The link opens correctly but I can't pass cloudflare.
Also, I see some errors on my console:
Thanks...
Try adding user agent argument in chrome options and set user agent to any value
ops = Options()
ua='me'
ops.add_argument('--user-agent=%s' % ua)
driver=uc.Chrome(executable_path=r"C:\chromedriver.exe",chrome_options=ops)
Alternatively try using undetected-chromedriver
import undetected_chromedriver as uc
from selenium import webdriver
options = webdriver.ChromeOptions()
options.add_argument("start-maximized")
driver = uc.Chrome(options=options)
driver.get("https://temp-mail.org/")
from selenium import webdriver`
import time
from selenium.webdriver.chrome.options import Options
options = webdriver.ChromeOptions()
options.add_argument("user-data-dir=C:\\Users\\avayn\\AppData\\Local\\Google\\Chrome\\User Data\\Default")
driver = webdriver.Chrome(executable_path=r'E:\chromedriver_win32\chromedriver.exe', chrome_options=options)
#options.add_argument("--disable-extensions")
driver.get("https://www.ea.com/tr-tr/fifa/ultimate-team/web-app/")
time.sleep(15)
transfer = browser.find_element_by_xpath("/html/body/main/section/nav/button[3]").click
Normally, I can login automatically, but my chrome profile is not loading.
I'm pretty new to programming.So i have this code its supposed to log me in at instagram but i doesnt works.
I tried to find it by x_path and other methods but didnt get it right.
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
import webbrowser
driver = webdriver.Chrome()
webbrowser.open('https://www.instagram.com/accounts/login/')
from selenium.webdriver.chrome.options import Options
chrome_options = Options()
chrome_options.add_argument("--disable-infobars")
browser = webdriver.Chrome(executable_path =
"C:\chromedriver",chrome_options=chrome_options)
browser = webbrowser
login_elem =
webbrowser.find_element_by_xpath('//article/div/div/p/a[text()="Anmelden"]')
login_elem.click()
driver.find_element_by_css_selector('.button.c_button.s_button').click()
ese.clickButton(Anmelden)