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

时间:2012-10-16 11:45:21

标签: python sockets selenium port

我在Mac上使用Selenium 2.25.0和Python 2.7.1绑定。我运行时遇到套接字错误:

# -*- 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

我试过摆弄不同的端口,但这并没有解决问题。如果有一些明显我在这里遗失的道歉,请道歉。谢谢你的帮助!

1 个答案:

答案 0 :(得分:2)

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

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