简体   繁体   中英

How to open Google chrome using selenium in a custom profile in python [Operating System: Ubuntu]

This is the code I had used

options = webdriver.ChromeOptions()
options.add_argument("user-data-dir=/home/user_name/.config/google-chrome/")
browser=webdriver.Chrome(executable_path='/usr/local/bin/chromedriver',chrome_options=options)
browser.get('https://www.google.co.in/')

The above code opens the browser in the required profile but the subsequent lines of is not executed (WebDriverException is thrown) and if the arguments inside webdriver.Chrome() is removed, browser loads 'google.co.in' .

Edit: The error message shown is:

  Traceback (most recent call last):
  File "test.py", line 30, in <module>
  browser = webdriver.Chrome(executable_path= '/usr/local/bin/chromedriver',chrome_options=options)
  File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/chrome/webdriver.py", line 69, in __init__
desired_capabilities=desired_capabilities)
  File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/remote/webdriver.py", line 90, in __init__
  self.start_session(desired_capabilities, browser_profile)
  File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/remote/webdriver.py", line 177, in start_session
  response = self.execute(Command.NEW_SESSION, capabilities)
  File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/remote/webdriver.py", line 236, in execute
  self.error_handler.check_response(response)
  File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/remote/errorhandler.py", line 192, in check_response
  raise exception_class(message, screen, stacktrace)
  selenium.common.exceptions.WebDriverException: Message: unknown error: Chrome failed to start: exited abnormally
(Driver info: chromedriver=2.22.397932 (282ed7cf89cf0053b6542e0d0f039d4123bbb6ad),platform=Linux 4.4.0-31-generic x86_64)

I faced the same issue and fixed it by using the latest version of chromedriver.

My current chrome version is v54, so I used chromedriver v2.25 which the release notes stated it supports Chrome v53-55.

https://chromedriver.storage.googleapis.com/index.html?path=2.25/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM