selenium.common.exceptions.WebDriverException:消息:服务 [英] selenium.common.exceptions.WebDriverException: Message: Service

查看:374
本文介绍了selenium.common.exceptions.WebDriverException:消息:服务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I had a trouble when i use selenium to control my Chrome. Here is my code:

from selenium import webdriver
driver = webdriver.Chrome()

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

When i tried to operate it ,it runs successfully at first,the Chrome pop on the screen. However, it shut down at the few seconds.

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

推荐答案

您需要提供chromedriver的路径...从

You need to provide the path of chromedriver...download from http://chromedriver.storage.googleapis.com/index.html?path=2.24/...unzip it and provide path to it in... webdriver.chrome ("path to chromedriver")

我在这里解释了这些事情:

I explain the things here:

from selenium import webdriver


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

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

This is the error if i run the above code:

    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在原始问题中提到的相同.

Which is same as mentioned by @Weiziyoung in original problem.

解决方案就像我提到的那样,您需要提供chromedriver的路径,而不是像chrome浏览器之类的

The solution is as I mentioned you need to provide the path to chromedriver in place of chrome browser like

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

它将解决问题

这篇关于selenium.common.exceptions.WebDriverException:消息:服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆