Python Selenium套接字错误 - [Errno 61]连接被拒绝

Python Selenium套接字错误 - [Errno 61]连接被拒绝

问题描述:

我在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 

我试着用不同的端口摆弄,但这并不能解决问题。道歉,如果有什么明显的我在这里失踪。谢谢你的帮助!

在运行脚本之前,您必须启动服务器。转到Selenium RC服务器所在的目录,然后从命令行控制台运行以下命令。您可以找到更多说明here

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

谢谢!哎呀,这很明显。 – DannyMatt