如何在python [操作系统:Ubuntu]的自定义配置文件中使用selenium打开Goog​​le Chrome

时间:2016-07-22 19:58:47

标签: python google-chrome selenium ubuntu

这是我用过的代码

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'。< / p>

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

  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)

0 个答案:

没有答案