I’m using the python version of selenium for some testing with django, but firefox webdriver is throwing an URLError exception when trying to start a new session. What I do is:
browser = webdriver.Firefox()
Update: then I do some testing, then I need to close it since the current test is done, but for the next one I need a fresh session, so I try to open a new one
browser.close()
capabilities = webdriver.DesiredCapabilities()
browser.start_session(capabilities.FIREFOX)
but then it throws this:
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>
The weird thing is that this same steps work perfectly fine with the Chrome webdriver.
Does anyone know why this could be caused?
Thanks in advance for any help
You shouldn’t have to use start_session for that.
On the first line, you are creating a new instance of a local firefox browser. start_session is a method for the remote webdriver.
All you need is:
Since you are repeating code here, you should have something like this inside your test class
That way the browser will launch at the beginning of each test and close at the end of each test.