【问题标题】:How to open Google chrome using selenium in a custom profile in python [Operating System: Ubuntu]如何在 python 的自定义配置文件中使用 selenium 打开 Google chrome [操作系统:Ubuntu]
【发布时间】:2016-11-26 19:50:58
【问题描述】:

这是我使用的代码

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/')

以上代码在所需配置文件中打开浏览器,但未执行后续行(引发 WebDriverException),如果 webdriver.Chrome() 中的参数被删除,浏览器将加载 'google.co.in' 。

编辑:显示的错误信息是:

  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)

【问题讨论】:

  • 你能发布整个异常消息吗?
  • 嗨,格雷格,我已经粘贴了异常消息。

标签: python google-chrome selenium ubuntu


【解决方案1】:

我遇到了同样的问题,并使用最新版本的 chromedriver 修复了它。

我当前的 chrome 版本是 v54,所以我使用了 chromedriver v2.25,发行说明声明它支持 Chrome v53-55。

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

【讨论】:

    猜你喜欢
    • 2022-12-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-05-15
    • 1970-01-01
    • 2018-09-02
    • 2021-04-04
    • 1970-01-01
    相关资源
    最近更新 更多