I am trying to open a chrome window that remembers my browser history, cookies, etc. I was able to do this by adding the Chrome Options, BUT when I add these options my driver.get() statement no longer works. The script just opens a chrome window but won't go to the specified website. If I remove the options it takes me to the website, but then I don't have the browser history data I want.
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
PATH = '/Users/myname/Projects/chromedriver'
options = webdriver.ChromeOptions()
options.add_argument('user-data-dir=/Users/myname/Library/Application Support/Google/Chrome/')
driver = webdriver.Chrome(executable_path=PATH, chrome_options=options)
driver.get('https://www.basketball-reference.com/')
I also receive this error:
Traceback (most recent call last):
File "app_store.py", line 9, in <module>
driver = webdriver.Chrome(executable_path=PATH, options=options)
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/selenium/webdriver/chrome/webdriver.py", line 81, in __init__
desired_capabilities=desired_capabilities)
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/selenium/webdriver/remote/webdriver.py", line 157, in __init__
self.start_session(capabilities, browser_profile)
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/selenium/webdriver/remote/webdriver.py", line 252, in start_session
response = self.execute(Command.NEW_SESSION, parameters)
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/selenium/webdriver/remote/webdriver.py", line 321, in execute
self.error_handler.check_response(response)
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/selenium/webdriver/remote/errorhandler.py", line 242, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.InvalidArgumentException: Message: invalid argument: user data directory is already in use, please specify a unique value for --user-data-dir argument, or don't use --user-data-dir
I think you've got a syntax error here
driver = webdriver.Chrome(executable_path=PATH, chrome_options=options)
The argument is just options, so it should be
driver = webdriver.Chrome(executable_path=PATH, options=options)
Try making two different drivers, one for Chrome Options and one for the website.
Related
I'm trying to open website in my real Chrome not a driver But i got list of Errors and it does't open the url**
Here is my code
from selenium import webdriver
from selenium.webdriver.chrome.service import Service
s = Service("C:\\Users\\Administrator\\Desktop\\chromedriver.exe")
options = webdriver.ChromeOptions()
options.add_argument("--user-data-dir=C:\\Users\\Administrator\\AppData\\Local\\Google\\Chrome\\User Data")
options.add_argument('--profile-directory=Default')
driver = webdriver.Chrome(service=s, chrome_options=options)
driver.get("https://www.instagram.com")
The Errors Like :
C:\Users\Administrator\Desktop\Py Sele\Sele.py:11: DeprecationWarning: use options instead of chrome_options
driver = webdriver.Chrome(service=s, chrome_options=options)
Opening in existing browser session.
Traceback (most recent call last):
File "C:\Users\Administrator\Desktop\Py Sele\Sele.py", line 11, in <module>
driver = webdriver.Chrome(service=s, chrome_options=options)
File "C:\Program Files\Python39\lib\site-packages\selenium\webdriver\chrome\webdriver.py", line 70, in __init__
super(WebDriver, self).__init__(DesiredCapabilities.CHROME['browserName'], "goog",
File "C:\Program Files\Python39\lib\site-packages\selenium\webdriver\chromium\webdriver.py", line 93, in __init__
RemoteWebDriver.__init__(
File "C:\Program Files\Python39\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 268, in __init__
self.start_session(capabilities, browser_profile)
File "C:\Program Files\Python39\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 359, in start_session
response = self.execute(Command.NEW_SESSION, parameters)
File "C:\Program Files\Python39\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 424, in execute
self.error_handler.check_response(response)
File "C:\Program Files\Python39\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 247, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.InvalidArgumentException: Message: invalid argument: user data directory is already in use, please specify a unique value for --user-data-dir argument, or don't use --user-data-dir
Stacktrace:
Backtrace:
This error message...
selenium.common.exceptions.InvalidArgumentException: Message: invalid argument: user data directory is already in use, please specify a unique value for --user-data-dir argument, or don't use --user-data-dir
...implies that the --user-data-dir is already in use.
Your main issue is you have already an open Google Chrome browser session opened for your manual browsing.
There is no such error in your code block. However it seems you are executing program as an Administrator. But,
A common cause for Chrome to crash during startup is running Chrome as root user (administrator) on Linux. While it is possible to work around this issue by passing --no-sandbox flag when creating your WebDriver session, such a configuration is unsupported and highly discouraged. You need to configure your environment to run Chrome as a regular user instead.
Solution
Before you execute your test as an user e.g. Administrator, ensure that you don't have any open Chrome browser windows using the same user i.e. Administrator.
i'm trying out Python Selenium with my main browser, Opera, but i get a massive error when i execute the script, here's the python script:
from selenium import webdriver
path = r"C:\Users\sleep\Programs\operadriver_win64\operadriver.exe"
driver = webdriver.Opera(executable_path=path)
driver.get('https://youtube.com')
And here's the error:
Traceback (most recent call last):
File "C:\Users\sleep\Programs\Status-Entrega\main.py", line 6, in <module>
driver = webdriver.Opera(executable_path=r'C:\Users\sleep\Programs\operadriver_win64\operadriver.exe')
File "C:\Users\sleep\AppData\Local\Programs\Python\Python39\lib\site-packages\selenium\webdriver\opera\webdriver.py", line 79, in __init__
OperaDriver.__init__(self, executable_path=executable_path,
File "C:\Users\sleep\AppData\Local\Programs\Python\Python39\lib\site-packages\selenium\webdriver\opera\webdriver.py", line 55, in __init__
ChromiumDriver.__init__(self,
File "C:\Users\sleep\AppData\Local\Programs\Python\Python39\lib\site-packages\selenium\webdriver\chrome\webdriver.py", line 76, in __init__
RemoteWebDriver.__init__(
File "C:\Users\sleep\AppData\Local\Programs\Python\Python39\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 157, in __init__
self.start_session(capabilities, browser_profile)
File "C:\Users\sleep\AppData\Local\Programs\Python\Python39\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 252, in start_session
response = self.execute(Command.NEW_SESSION, parameters)
File "C:\Users\sleep\AppData\Local\Programs\Python\Python39\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 321, in execute
self.error_handler.check_response(response)
File "C:\Users\sleep\AppData\Local\Programs\Python\Python39\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 242, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.WebDriverException: Message: unknown error: cannot find Opera binary
(Driver info: operadriver=91.0.4472.77 (1cecd5c8a856bc2a5adda436e7b84d8d21b339b6-refs/branch-heads/4472#{#1246}),platform=Windows NT 10.0.19042 x86_64)
How can i fix this?
can you try this :
from selenium import webdriver
from selenium.webdriver.opera.options import Options
options = Options()
options.binary_location = r'C:\opera.exe path'
driver = webdriver.Opera(opera_options = options,
executable_path=r'C:\operadriver.exe path')
it might work, don't forget one is the opera path and one is the operadriver path
This link may help: https://github.com/operasoftware/operachromiumdriver/blob/master/examples/desktop.py
import time
from selenium import webdriver
from selenium.webdriver.chrome import service
webdriver_service = service.Service('path/to/operadriver')
webdriver_service.start()
driver = webdriver.Remote(webdriver_service.service_url, webdriver.DesiredCapabilities.OPERA)
driver.get('https://www.google.com/')
input_txt = driver.find_element_by_name('q')
input_txt.send_keys('operadriver\n')
time.sleep(5) #see the result
driver.quit()
I have a problem, every, single, TIME
Basically this is my code:
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
options = Options()
options.binary_location = "C:\Program Files (x86)\Google\Chrome Beta\Application\chrome.exe"
options.add_argument("--no-sandbox")
options.add_argument("--no-default-browser-check")
options.add_argument("--no-first-run")
options.add_argument("--disable-default-apps")
driver = webdriver.Chrome(options=options, executable_path="C:\Program Files (x86)\Google\Chrome Beta\Application\chromedriver.exe")
driver.get('https://www.youtube.com/')
and the error is
selenium.common.exceptions.SessionNotCreatedException: Message: session not created
I used Pycharm and tried to use VS code with python 3.4 and 3.7 and 3.8.3
plz help me I'm getting tired of this.
Full error Log:
Traceback (most recent call last):
File "C:/Users/um/PycharmProjects/Selenium/main.py", line 10, in <module>
driver = webdriver.Chrome(options=options, executable_path="C:\Program Files (x86)\Google\Chrome Beta\Application\chromedriver.exe")
File "C:\Users\um\AppData\Local\Programs\Python\Python38-32\lib\site-packages\selenium\webdriver\chrome\webdriver.py", line 76, in __init__
RemoteWebDriver.__init__(
File "C:\Users\um\AppData\Local\Programs\Python\Python38-32\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 157, in __init__
self.start_session(capabilities, browser_profile)
File "C:\Users\um\AppData\Local\Programs\Python\Python38-32\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 252, in start_session
response = self.execute(Command.NEW_SESSION, parameters)
File "C:\Users\um\AppData\Local\Programs\Python\Python38-32\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 321, in execute
self.error_handler.check_response(response)
File "C:\Users\um\AppData\Local\Programs\Python\Python38-32\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 242, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.SessionNotCreatedException: Message: session not created
from disconnected: unable to send message to renderer
(Session info: chrome=81.0.4044.83)
Your error is not
unable to send message to renderer
as you mentioned. According to the stack trace you posted the problem in the line 6
driver = webdriver.Chrome(options=options, executable_path="chromedriver.exe", )
and the problem is:
selenium.common.exceptions.SessionNotCreatedException: Message: session not created
It seems like you specified an invalid path to the chromedriver and Selenium is unable to initialize the driver and create a session.
You should also check the version of the chromedriver with the guide.
Here you can download the valid version (I have taken your Chrome version from the stacktrace).
yes it did start and then close with the error log above, and also i have the correct version
I am working on a web application, and was attempting to run a basic test script with seleium, just to make sure my code was working
from selenium import webdriver
import time
import os
options = webdriver.ChromeOptions()
options.add_argument('--ignore-certificate-errors')
options.add_argument("--test-type")
options.binary_location = os.getcwd()
driver = webdriver.Chrome(chrome_options=options, executable_path=r'./chromedriver')
driver.get('http://codepad.org')
I have the chromedriver in the current directory, and I think I am using the correct version of the chromedriver (75.0.3770.90). The full error I am getting is:
Traceback (most recent call last):
File "test.py", line 9, in <module>
driver = webdriver.Chrome(options=options, executable_path=r'./chromedriver')
File "/Users/kylerood/Documents/summer19/makeFriends/env/lib/python3.7/site-packages/selenium/webdriver/chrome/webdriver.py", line 81, in __init__
desired_capabilities=desired_capabilities)
File "/Users/kylerood/Documents/summer19/makeFriends/env/lib/python3.7/site-packages/selenium/webdriver/remote/webdriver.py", line 157, in __init__
self.start_session(capabilities, browser_profile)
File "/Users/kylerood/Documents/summer19/makeFriends/env/lib/python3.7/site-packages/selenium/webdriver/remote/webdriver.py", line 252, in start_session
response = self.execute(Command.NEW_SESSION, parameters)
File "/Users/kylerood/Documents/summer19/makeFriends/env/lib/python3.7/site-packages/selenium/webdriver/remote/webdriver.py", line 321, in execute
self.error_handler.check_response(response)
File "/Users/kylerood/Documents/summer19/makeFriends/env/lib/python3.7/site-packages/selenium/webdriver/remote/errorhandler.py", line 242, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.WebDriverException: Message: unknown error: Failed to create a Chrome process.
If anyone has any insight into a fix I could try that would be greatly appreciated!
Remove/comment the below line.
options.binary_location = os.getcwd()
As the binary is not located in the current working directory you are getting this error message.
binary_location is the location where your chrome.exe is located.
And make sure you have the chromedriver in the same folder you have this test located. Otherwise your script will fail with below error message.
selenium.common.exceptions.WebDriverException: Message: 'chromedriver` executable needs to be in PATH. Please see https://sites.google.com/a/chromium.org/chromedriver/home
The value binary_location must be an .exe file which specify the chrome.exe you want to run.
So this code works for me:
chrome_options = Options()
chrome_options.binary_location = '****\\chrome.exe'
driver = webdriver.Chrome(executable_path=os.path.abspath("chromedriver\\chromedriver.exe"), options=chrome_options)
Hope it helps you
Here's my code and the error Python provides.
I'm a beginner using Python 3.6. Can anyone helps find out what's wrong? Many thanks.
#!/usr/bin/env python
#coding: utf-8
from selenium import webdriver
driver = webdriver.Chrome('C:\\Users\\Admin\\AppData\\Local\\Google\\Chrome\\Application\\chromedriver.exe')
browser = webdriver.Chrome()
browser.get('http://www.bing.com/')
Traceback:
Traceback (most recent call last):
File "C:\Users\Admin\Desktop\cxy61.com - html\python spider\001 selenium import.py", line 8, in <module>
driver = webdriver.Chrome('C:\\Users\\Admin\\AppData\\Local\\Google\\Chrome\\Application\\chromedriver.exe')
File "C:\Users\Admin\AppData\Local\Programs\Python\Python36\lib\site-packages\selenium\webdriver\chrome\webdriver.py", line 69, in __init__
desired_capabilities=desired_capabilities)
File "C:\Users\Admin\AppData\Local\Programs\Python\Python36\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 140, in __init__
self.start_session(desired_capabilities, browser_profile)
File "C:\Users\Admin\AppData\Local\Programs\Python\Python36\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 229, in start_session
response = self.execute(Command.NEW_SESSION, parameters)
File "C:\Users\Admin\AppData\Local\Programs\Python\Python36\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 297, in execute
self.error_handler.check_response(response)
File "C:\Users\Admin\AppData\Local\Programs\Python\Python36\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 194, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.WebDriverException: Message: session not created exception: Chrome version must be >= 58.0.3029.0
(Driver info: chromedriver=2.31.488763 (092de99f48a300323ecf8c2a4e2e7cab51de5ba8),platform=Windows NT 10.0.14393 x86_64)
You have to take care of a couple of things as follows:
As you are using chromedriver v2.31 the error clearly states Chrome version must be >= 58.0.3029.0. So you need to bump up your Google Chrome version to v58.0 or above.
If you want to specify the absolute path of the chromedriver within single quotes '...' then you have to provide single forward slashes \ only.
If you are assigning the webdriver instance to the driver, you have to use the driver instance only to open any url
Here is your own code with the above mentioned changes:
from selenium import webdriver
driver = webdriver.Chrome(r'C:\Utility\BrowserDrivers\chromedriver.exe')
driver.get('http://www.bing.com/')