Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
214 views
in Technique[技术] by (71.8m points)

python - WebDriverException: Message: 'Can not connect to the ChromeDriver'. Error in utils.is_connectable(self.port):

I am trying to use the chromedriver 2.10 to run my tests on Chrome Browser Version 35.0.1916.114 On CentOS machine

/home/varunm/EC_WTF_0.4.10/EC_WTF0.4.10_Project/wtframework/wtf/drivers/chromedriver

Actually I fixed the path issue, because the error message was different if the issue was with path

    def start(self):
    """
    Starts the ChromeDriver Service.

    :Exceptions:
     - WebDriverException : Raised either when it can't start the service
       or when it can't connect to the service
    """
    env = self.env or os.environ
    try:
        self.process = subprocess.Popen([
          self.path,
          "--port=%d" % self.port] +
          self.service_args, env=env, stdout=PIPE, stderr=PIPE)
    except:
        raise WebDriverException(
            "ChromeDriver executable needs to be available in the path. 
            Please download from http://chromedriver.storage.googleapis.com/index.html
            and read up at http://code.google.com/p/selenium/wiki/ChromeDriver")
    count = 0
    while not utils.is_connectable(self.port):
        count += 1
        time.sleep(1)
        if count == 30:
             raise WebDriverException("Can not connect to the ChromeDriver")

If the path was wrong I will receive some other error, but now the error is while making the connection

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)


For Linux

1. Check you have installed latest version of chrome brwoser-> "chromium-browser -version"
2. If not, install latest version of chrome "sudo apt-get install chromium-browser"
3. get appropriate version of chrome driver from following link http://chromedriver.storage.googleapis.com/index.html
4. Unzip the chromedriver.zip
5. Move the file to /usr/bin/ directory sudo mv chromedriver /usr/bin/
6. Goto /usr/bin/ directory and you would need to run something like "chmod a+x chromedriver" to mark it executable.
7. finally you can execute the code.

import os
from selenium import webdriver
from pyvirtualdisplay import Display
display = Display(visible=0, size=(800, 600))
display.start()
driver = webdriver.Chrome()
driver.get("http://www.google.com")
print driver.page_source.encode('utf-8')
driver.quit()
display.stop()

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...