【问题标题】:selenium.common.exceptions.WebDriverException: Message: Serviceselenium.common.exceptions.WebDriverException:消息:服务
【发布时间】:2017-02-21 05:44:51
【问题描述】:

我在使用 selenium 控制 Chrome 时遇到了麻烦。 这是我的代码:

from selenium import webdriver
driver = webdriver.Chrome()

当我尝试操作它时,它首先运行成功,屏幕上弹出Chrome。但是,它在几秒钟内关闭。

Traceback (most recent call last):
  File "<pyshell#3>", line 1, in <module>
    driver = webdriver.Chrome('C:\Program Files (x86)\Google\Chrome\chrome.exe')
  File "C:\Users\35273\AppData\Local\Programs\Python\Python35\lib\site-packages\selenium\webdriver\chrome\webdriver.py", line 62, in __init__
    self.service.start()
  File "C:\Users\35273\AppData\Local\Programs\Python\Python35\lib\site-packages\selenium\webdriver\common\service.py", line 86, in start
    self.assert_process_still_running()
  File "C:\Users\35273\AppData\Local\Programs\Python\Python35\lib\site-packages\selenium\webdriver\common\service.py", line 99, in assert_process_still_running
    % (self.path, return_code)
selenium.common.exceptions.WebDriverException: Message: Service C:\Program Files (x86)\Google\Chrome\chrome.exe unexpectedly exited. Status code was: 0

【问题讨论】:

    标签: google-chrome python-3.x selenium selenium-webdriver web-crawler


    【解决方案1】:

    您需要提供chromedriver的路径...从http://chromedriver.storage.googleapis.com/index.html?path=2.24/...unzip下载它并在... webdriver.chrome ("path to chromedriver")中提供它的路径

    我在这里解释一下:

    from selenium import webdriver
    
    
    driver = webdriver.Chrome("C:\Program Files (x86)\Google\Chrome\Application\chrome.exe")
    

    如果我运行上面的代码,这是错误:

        C:\Python27\python.exe C:/Users/Gaurav.Gaurav-PC/PycharmProjects/Learning/StackOverflow/SeleniumQuestion/test123.py
        Traceback (most recent call last):
          File "C:/Users/Gaurav.Gaurav-PC/PycharmProjects/Learning/StackOverflow/SeleniumQuestion/test123.py", line 4, in <module>
            driver = webdriver.Chrome("C:\Program Files (x86)\Google\Chrome\Application\chrome.exe")
          File "C:\Python27\lib\site-packages\selenium\webdriver\chrome\webdriver.py", line 62, in __init__
            self.service.start()
          File "C:\Python27\lib\site-packages\selenium\webdriver\common\service.py", line 86, in start
            self.assert_process_still_running()
          File "C:\Python27\lib\site-packages\selenium\webdriver\common\service.py", line 99, in assert_process_still_running
            % (self.path, return_code)
        selenium.common.exceptions.WebDriverException: Message: Service C:\Program Files (x86)\Google
    
    \Chrome\Application\chrome.exe unexpectedly exited. Status code was: 0
    

    这与@Weiziyoung 在原始问题中提到的相同。

    解决方案正如我所提到的,您需要提供 chromedriver 的路径来代替 chrome 浏览器,例如

    driver = webdriver.Chrome("E:\Jars\chromedriver.exe")
    

    解决问题

    【讨论】:

    • OP 不需要指定文件的直接路径,因为 chromedriver 似乎已经在 Path 中。如果找不到chromedriver 二进制文件,则应提出selenium.common.exceptions.WebDriverException: Message: 'chromedriver' executable needs to be in PATH. 之类的内容
    • 不,我已经添加了环境变量的路径。
    • 我认为它在错误行 1 中给出了 chrome 浏览器的路径而不是 chromedriver,您可以看到它
    • 你想错了!这应该是chromedriver 的路径,而不是Chrome 二进制文件。检查这个:sites.google.com/a/chromium.org/chromedriver/getting-started
    • 如果我不能正确地写来解释我的观点,我很抱歉。我是说看起来 chrome 二进制文件的路径是由用户查看错误而不是 chromedriver 给出的
    【解决方案2】:

    下载相应的驱动:http://chromedriver.storage.googleapis.com/index.html 打开 E:\Python37\Scripts

    【讨论】:

      【解决方案3】:

      我遇到了同样的错误(behave.step_registry.AmbiguousStep: @given('Lunch chrome Browser') 已经在 features/steps/OrangeHRMlogin.py:4 的现有步骤 @given('Lunch chrome Browser') 中定义)。我认为它需要以前提到“午餐铬浏览器”的程序。所以我做了一些改变,比如我在 (U'chrome browser') 上的第二个程序。更改浏览器名称或阶段,它运行成功。

      【讨论】:

        【解决方案4】:

        原来的 chrome 浏览器被打开而不是 chrome 驱动程序,这是错误下载 chrome 驱动程序并给出它的路径的原因

        【讨论】:

          猜你喜欢
          • 2017-11-30
          • 1970-01-01
          • 1970-01-01
          • 2017-08-31
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2019-03-30
          相关资源
          最近更新 更多