我正在使用 selenium 的 python 版本对 django 进行一些测试,但是 firefox webdriver 在尝试启动新会话时抛出 URLError 异常。我要做的是:
browser = webdriver.Firefox()
更新:然后我做了一些测试,然后我需要关闭它,因为当前测试已经完成,但是对于下一个我需要一个新的会话,所以我尝试打开一个新的
browser.close()
capabilities = webdriver.DesiredCapabilities()
browser.start_session(capabilities.FIREFOX)
但随后它抛出了这个:
Traceback (most recent call last):
File "<console>", line 1, in <module>
File "/home/user/projects/myproject/local/lib/python2.7/site-packages/selenium/webdriver/remote/webdriver.py", line 104, in start_session
'desiredCapabilities': desired_capabilities,
File "/home/user/projects/myproject/local/lib/python2.7/site-packages/selenium/webdriver/remote/webdriver.py", line 153, in execute
response = self.command_executor.execute(driver_command, params)
File "/home/user/projects/myproject/local/lib/python2.7/site-packages/selenium/webdriver/remote/remote_connection.py", line 285, in execute
return self._request(url, method=command_info[0], data=data)
File "/home/user/projects/myproject/local/lib/python2.7/site-packages/selenium/webdriver/remote/remote_connection.py", line 326, in _request
response = opener.open(request)
File "/usr/lib/python2.7/urllib2.py", line 400, in open
response = self._open(req, data)
File "/usr/lib/python2.7/urllib2.py", line 418, in _open
'_open', req)
File "/usr/lib/python2.7/urllib2.py", line 378, in _call_chain
result = func(*args)
File "/usr/lib/python2.7/urllib2.py", line 1207, in http_open
return self.do_open(httplib.HTTPConnection, req)
File "/usr/lib/python2.7/urllib2.py", line 1177, in do_open
raise URLError(err)
URLError: <urlopen error [Errno 111] Connection refused>
奇怪的是,同样的步骤在 Chrome 网络驱动程序上运行得很好。
有谁知道为什么会这样?提前感谢您的帮助