When I run this code
import time
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
chrome_options = Options()
chrome_options.add_argument("--disable-infobars")
chrome_options.add_argument("--start-maximized")
chrome_options.add_argument(r"user-data-dir=C:\Users\micha\AppData\Local\Google\Chrome\User Data\Profile 1")
driver = webdriver.Chrome(executable_path=r'C:\Users\micha\Desktop\Visual_projects\chromedriver.exe', chrome_options = chrome_options)
driver.get("https://store.steampowered.com/")
This error pops up : [12216:1336:0411/232857.718:ERROR:browser_switcher_service.cc(238)] XXX Init()
Could someone please help me. I don't know what is wrong but the programm won't open the new profile I created. Any help would be appreciated.
I searched everywhere how to fix this error but I think the guides are outdated
Check your Chrome browser version and your Chrome webdriver version. If both are same then issue should be solved.
One thing to check would be, if your ChromeDriver-Executable matches the version of the Chrome you have installed (under Help/About Google Chrome in your browser). There are versions 79, 80 and 81 mostly in use. You can find the current ChromeDrivers for all three versions here: https://chromedriver.chromium.org/downloads.
Related
I need to load my own Default chrome profile where all my saved login info is, instead of selenium logging me into my websites.
I have taken this code from stackoverflow, cannot find the exact user. My issue with this code is selenium opens chrome but does not load the correct profile. Every time I open run the code it creates a new "scoped_dir" folder and runs the profile "default" from there chrome version
(C:\Users\farja\AppData\Local\Temp\scoped_dir[bunch of numbers]\Default).
I have tried closing chrome and then running my code which doesn't work
I am thinking there is a big flaw in my code but do not know what it is or how to find it. A relevant answer for 2022 would be very very much appreciated as I have literally been stuck on this for a week now and have tried multiple answers on stackoverflow, the web and youtube but nearly all give me a deprecation error.
Thank you for taking the time to read.
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.chrome.service import Service
ser = Service(r'C:\Users\farja\Documents\Instagram Programmes\Scheduler 2\chromedriver')
op = webdriver.ChromeOptions()
s = webdriver.Chrome(service=ser, options=op)
op.add_argument(r"--user-data-dir=C:\\Users\\farja\\AppData\\Local\\Google\\Chrome\\User Data")
op.add_argument("--profile-directory=Default")
s.get("chrome://version/")
As your usecase is to load the Default Chrome Profile you can use the argument user-data-dir and remove the argument --profile-directory as follows:
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.chrome.service import Service
op = webdriver.ChromeOptions()
op.add_argument(r"--user-data-dir=C:\\Users\\farja\\AppData\\Local\\Google\\Chrome\\User Data\\Default")
ser = Service(r'C:\Users\farja\Documents\Instagram Programmes\Scheduler 2\chromedriver')
s = webdriver.Chrome(service=ser, options=op)
s.get("chrome://version/")
References
You can find a couple of relevant detailed discussions in:
How to open a Chrome Profile through Python
How to open a Chrome Profile through --user-data-dir argument of Selenium
What I have now is:
chrome_options = Options()
chrome_options.add_extension(r"C:\Users\x\OneDrive\Desktop\pp\crxSolver.crx")
driver = webdriver.Chrome(r'C:\Users\x\OneDrive\Desktop\chromedriver.exe', options=chrome_options)
driver.get("https://www.google.com")
I am able to open the webdriver and I see the extension that I added on the right top corner in google Chrome, however the driver doesn't go to google.com. I have searched a lot and I can't find the solution to it.
Here is the link to the extension:
https://chrome.google.com/webstore/detail/buster-captcha-solver-for/mpbjkejclgfgadiemmefgebjfooflfhl/related
Watch the video here for complete information
Try upgrading to chrome 75, your issue should resolve. Seems to be some issue with the machine and your browser compatibility.
How can Selenium Chrome WebDriver notifications be handled in Python?
Have tried to dismiss/accept alert and active element but seems notifications have to be treated other way. Also, all the Google search results are driving me to Java solution which I do not really need. I'm a newbie in Python.
Thanks in advance.
You can disable the browser notifications, using chrome options.
chrome_options = webdriver.ChromeOptions()
prefs = {"profile.default_content_setting_values.notifications" : 2}
chrome_options.add_experimental_option("prefs",prefs)
driver = webdriver.Chrome(chrome_options=chrome_options)
In December, 2021, using ChromeDriver Version: 96, the python code structure would look like below to handle the ChromeDriver/ Browser notification:
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
# Creating Instance
option = Options()
# Working with the 'add_argument' Method to modify Driver Default Notification
option.add_argument('--disable-notifications')
# Passing Driver path alongside with Driver modified Options
browser = webdriver.Chrome(executable_path= your_chrome_driver_path, chrome_options= option)
# Do your stuff and quit your driver/ browser
browser.get('https://www.google.com')
browser.quit()
The answer above from Dec '16 didn't work for me in August 2020. Both Selenium and Chrome have changed, I believe.
I'm using the binary for Chrome 84, which is listed as the current version, even though there's a binary for Chrome 85 available from selenium.dev. I have to presume that's a beta since I have no other info on that.
I only have a partial answer so far, but I believe the following two lines are in the right direction. They're as far as I've gotten tonight. I have a test window that I've opened to Facebook and have the exact window shown in the Question. The code given in pythonjar's answer from Dec 30 '16 above produced error messages for me. These code lines worked without error, so I believe this is the right track.
>>> from selenium.webdriver import ChromeOptions
>>> chrome_options = ChromeOptions()
I'll update this tomorrow, if I get time to work on it.
Sorry for the partial answer. I hope to complete it soon. I hope this helps. If you get there first, please let me know.
Using Chrome Versão 85.0.4183.83 (Versão oficial) 64 bits and ChromeDriver 85.0.4183.83
Here is the code and it is working:
from selenium import webdriver
chrome_options = webdriver.ChromeOptions()
prefs = {"profile.default_content_setting_values.notifications" : 2}
chrome_options.add_experimental_option("prefs",prefs)
driver = webdriver.Chrome(chrome_options=chrome_options)
driver.get("https://www.google.com/")
2020/08/27
Follow the below code for handling the notification settings with Python selenium
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
option = Options()
option.add_argument("--disable-infobars")
option.add_argument("start-maximized")
option.add_argument("--disable-extensions")
option.add_experimental_option("prefs",
{"profile.default_content_setting_values.notifications": 2
})
Note 1-to allow notification, 2- to block notification
I try to use Python to log in a web, type in use id and password, and download some files. however, before logging the page, there is a error msg says
"Failed to load extension from
C:\User\xyz\AppData\Local\Temp\scoped_dir12188_17478\internal. Loading
of unpacked extensions is disabled by administrator"
. After I hit "Enter", the rest goes well.
I have searched here, and find one post is related to my question, Here. But the code is still not working for me. the pop up error windows is still showing up. Any ideas or suggestion is highly welcome. Thank you!
Here is my code:
import time
import urllib3
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.chrome.options import Options
driverpath = 'C:\\Users\\xyz\\AppData\\Local\\Programs\\Python\\Python36\\chromedriver.exe'
chrome_options = Options()
chrome_options.add_argument("--disable-extensions")
browser = webdriver.Chrome(executable_path=driverpath, chrome_options=chrome_options)
url ='https://userid:password#weblink'
browser.get(url)
Running latest version of all features
(chrome version 66, selenium version 3.12, chromedriver version 2.39, python version 3.6.5)
I have tried all of the solutions that I have found online but nothing seems to be working. I have automated something using Selenium for Chrome and it does exactly what I need it to do.
The last thing I need to to is hide the browser because I do not need to see the UI. I have attempted to make the browser headless using the following code but when I do the program crashes.
I have also tried to alter the window size to 0x0 and even tried the command: options.set_headless(headless=True) instead but nothing seems to work.
NOTE: I am running on Windows and have also tried with the command:
options.add_argument('--disable-gpu')
Try to move browser over the monitor
driver = webdriver.Chrome()
driver.set_window_position(-2000,0) # if -20000 don't help put -10000
What is happening when you run, does it produce any error or just run as if you hadn't even added the headless argument?
Here's what I do for mine to run headlessly -
from selenium import webdriver
options = webdriver.ChromeOptions()
options.add_argument('--headless')
options.add_argument('--disable-gpu')
selenium_chrome_driver_path = "blah blah my path is here"
my_driver = webdriver.Chrome(chrome_options = options, executable_path = selenium_chrome_driver_path)
I'm running this code with python 3.6 with up to date selenium drivers on Windows 8 (unfortunately)
Got the solutions after combining a few sources. It seems that the libraries get often updated and eventually it becomes deprecated. Atm this one worked for me in Windows, using Python 3.4:
from selenium import webdriver
options = webdriver.ChromeOptions()
options.headless = True
driver = webdriver.Chrome(executable_path="C:/Users/Admin/Documents/chromedriver_win32/chromedriver", options=options)
Try to use user agent in chrome_options
ua = UserAgent()
userAgent = ua.random
print(userAgent)
chrome_options.add_argument('user-agent={userAgent}')