Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

selenium.common.exceptions.WebDriverException: Message: Service

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

from selenium import webdriver
driver = webdriver.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. 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
like image 806
Weiziyoung Avatar asked Oct 12 '16 12:10

Weiziyoung


1 Answers

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

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

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")

It will resolve the problem

like image 176
thebadguy Avatar answered Jan 02 '23 09:01

thebadguy