【问题标题】:Failed to launch chrome with selenium webdriver in python无法在 python 中使用 selenium webdriver 启动 chrome
【发布时间】:2017-09-28 11:45:45
【问题描述】:
import selenium
from selenium import webdriver   
webdriver.Chrome()

python -m pytest swim/tests/filename.py

给出错误:-

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/ganesh/.virtualenvs/uniq/lib/python3.5/site-packages/selenium/webdriver/chrome/webdriver.py", line 69, in __init__
    desired_capabilities=desired_capabilities)
  File "/home/ganesh/.virtualenvs/uniq/lib/python3.5/site-packages/selenium/webdriver/remote/webdriver.py", line 151, in __init__
    self.start_session(desired_capabilities, browser_profile)
  File "/home/ganesh/.virtualenvs/uniq/lib/python3.5/site-packages/selenium/webdriver/remote/webdriver.py", line 240, in start_session
    response = self.execute(Command.NEW_SESSION, parameters)
  File "/home/ganesh/.virtualenvs/uniq/lib/python3.5/site-packages/selenium/webdriver/remote/webdriver.py", line 308, in execute
    self.error_handler.check_response(response)
  File "/home/ganesh/.virtualenvs/uniq/lib/python3.5/site-packages/selenium/webdriver/remote/errorhandler.py", line 194, in check_response
    raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.WebDriverException: Message: unknown error: Chrome failed to start: exited abnormally
  (Driver info: chrome-driver=2.30,platform=Linux 4.10.0-35-generic x86_64)

在运行测试用例时,浏览器没有启动,我尝试了什么

  • 尝试设置 chrome-driver 和 chromium-browser 的路径。
  • 尝试卸载在python中安装chrome浏览器、chrome-driver和selenium。
  • 在很多建议中我都看到了这个 Xvfb -ac :99 -screen 0 1280x1024x16 所以我也尝试了这个。

任何帮助会很好吗??

【问题讨论】:

    标签: python-2.7 selenium-webdriver selenium-chromedriver


    【解决方案1】:

    也许,你没有设置 chrome 驱动目录:-

    from selenium import webdriver
    
    driver = webdriver.Chrome('/path/to/chromedriver')  # Optional argument, if not specified will search path. 
    

    For official documents

    【讨论】:

    • 试过了,但问题依旧。
    • @GaneshNagendran 您需要在 virtualenv 中安装 selenium,并且 chrome 驱动程序文件应该在 virtualenv 文件夹中。 Refrence
    【解决方案2】:

    所以,从这里获取 chrome 驱动器(官方 chrome 页面):

    https://sites.google.com/a/chromium.org/chromedriver/downloads

    然后解压并引入你的selenium文件夹->webdriver;我的例子是:

    C:\Python27\selenium\webdriver
    
    then system property->advanced system settings->Environment Variables->Path
    

    这里点击编辑,不要删除任何内容,只需在此处添加“;”你的路

    例如我添加了

    ;C:\Python27\selenium\webdriver
    

    如果您需要其他帮助,请告诉我

    【讨论】:

    • 添加 chrome web 驱动程序路径后,它也没有启动浏览器。问题不在于 chrome 驱动程序,因为当我在浏览器外部启动终端时工作正常。只有测试用例它没有启动。
    • mmmm 根据您的 chrome 版本,您是否拥有正确版本的 chromedrive?我真的没有别的想法了:对不起
    【解决方案3】:
    I have uninstalled Chrome driver and Selenium and re-installed the latest versions of it.Important thing is to set the path for it. Follow the mentioned steps which helped me.
    
    Command to upgrade Selenium:
    
    **pip install -U selenium**
    
    Use the below commands in order to install google chrome:
    1.  Add Key:
        wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | sudo apt-key add -
    2.  Set repository:
        sudo sh -c 'echo "deb [arch=amd64] http://dl.google.com/linux/chrome/deb/ stable main" >>/etc/apt/sources.list.d/google-chrome.list'
    3.  Install package:
        sudo apt-get update 
        sudo apt-get install google-chrome-stable
    
    4.  check the installed version [ ex:- google-chrome --version]
    
    Install chrome driver
    1.  Download chromedriver for linux 64 bit from 
        https://sites.google.com/a/chromium.org/chromedriver/downloads
    2.  unzip the file [ ex:- unzip chromedriver_linux64.zip ]
    3.  Move the binary to /opt location [ex:- sudo mv chromedriver /opt/ ]
    4.  Create symlink the chromedriver to system path [ex:- sudo ln -s /opt/chromedriver /usr/local/bin/chromedriver ]
    6.  check the chromedriver version [ex:- chromedriver --version ]
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-04-26
      • 2017-08-12
      • 1970-01-01
      • 2021-05-16
      • 1970-01-01
      • 2019-06-18
      • 2021-04-12
      • 2015-02-28
      相关资源
      最近更新 更多