我在 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
我试过摆弄不同的端口,但这并不能解决问题。抱歉,如果我在这里遗漏了一些明显的东西。谢谢你的帮助!