2012-10-16 210 views
1

我在Mac上使用Selenium 2.25.0與Python 2.7.1綁定。我遇到一個套接字錯誤,當我運行此:Python Selenium套接字錯誤 - [Errno 61]連接被拒絕

# -*- coding: utf-8 -*- 
from selenium import webdriver 
from selenium.webdriver.common.keys import Keys 
from selenium import selenium 
import unittest, time, re, base64, urllib, httplib, urllib2 

#Create Selenium object 
browser = selenium("localhost", 4444, "*firefox", "http://www.google.com/") 
#Start browser 
browser.start() 

,然後在最後一步(browser.start)我得到這個錯誤:

Traceback (most recent call last): 
    File "<stdin>", line 1, in <module> 
    File "/Library/Python/2.7/site-packages/selenium-2.25.0-py2.7.egg/selenium/selenium.py", line 189, in start 
    result = self.get_string("getNewBrowserSession", start_args) 
    File "/Library/Python/2.7/site-packages/selenium-2.25.0-py2.7.egg/selenium/selenium.py", line 223, in get_string 
    result = self.do_command(verb, args) 
    File "/Library/Python/2.7/site-packages/selenium-2.25.0-py2.7.egg/selenium/selenium.py", line 212, in do_command 
    conn.request("POST", "/selenium-server/driver/", body, headers) 
    File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/httplib.py", line 941, in request 
    File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/httplib.py", line 975, in _send_request 
    File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/httplib.py", line 937, in endheaders 
    File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/httplib.py", line 797, in _send_output 
    File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/httplib.py", line 759, in send 
    File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/httplib.py", line 740, in connect 
    File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/socket.py", line 571, in create_connection 
socket.error: [Errno 61] Connection refused 

我試着用不同的端口擺弄,但這並不能解決問題。道歉,如果有什麼明顯的我在這裏失蹤。謝謝你的幫助!

回答

2

在運行腳本之前,您必須啓動服務器。轉到Selenium RC服務器所在的目錄,然後從命令行控制檯運行以下命令。您可以找到更多說明here

java -jar selenium-server-standalone-<version-number>.jar 
+0

謝謝!哎呀,這很明顯。 – DannyMatt

相關問題