selenium.common.exceptions.WebDriverException:消息:服务

时间:2016-10-12 12:13:31

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

当我使用硒来控制我的Chrome时遇到了麻烦。 这是我的代码:

from selenium import webdriver
driver = webdriver.Chrome()

当我尝试操作时,它首先成功运行,Chrome在屏幕上弹出。然而,它在几秒钟后关闭。 Here is the Traceback information

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

4 个答案:

答案 0 :(得分:5)

你需要提供chromedriver的路径...从http://chromedriver.storage.googleapis.com/index.html?path=2.24/...unzip下载它并在... webdriver.chrome(“路径到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")

它将解决问题

答案 1 :(得分:0)

下载适当的驱动程序:http://chromedriver.storage.googleapis.com/index.html 打开E:\ Python37 \ Scripts <-将chromedriver.exe文件粘贴到

答案 2 :(得分:0)

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

答案 3 :(得分:0)

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