Sometimes, in the middle of my script, my webdriver instance will just die!
And thenceforth, I can't invoke any of its methods.
Some examples:
>>> spsel.driver.current_url
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python2.6/dist-packages/selenium/webdriver/remote/webdriver.py", line 414, in current_url
return self.execute(Command.GET_CURRENT_URL)['value']
File "/usr/local/lib/python2.6/dist-packages/selenium/webdriver/remote/webdriver.py", line 151, in execute
response = self.command_executor.execute(driver_command, params)
File "/usr/local/lib/python2.6/dist-packages/selenium/webdriver/remote/remote_connection.py", line 280, in execute
return self._request(url, method=command_info[0], data=data)
File "/usr/local/lib/python2.6/dist-packages/selenium/webdriver/remote/remote_connection.py", line 321, in _request
response = opener.open(request)
File "/usr/lib/python2.6/urllib2.py", line 391, in open
response = self._open(req, data)
File "/usr/lib/python2.6/urllib2.py", line 409, in _open
'_open', req)
File "/usr/lib/python2.6/urllib2.py", line 369, in _call_chain
result = func(*args)
File "/usr/lib/python2.6/urllib2.py", line 1161, in http_open
return self.do_open(httplib.HTTPConnection, req)
File "/usr/lib/python2.6/urllib2.py", line 1136, in do_open
raise URLError(err)
urllib2.URLError: <urlopen error [Errno 111] Connection refused>
>>> spsel.driver.quit()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python2.6/dist-packages/selenium/webdriver/firefox/webdriver.py", line 55, in quit
RemoteWebDriver.quit(self)
File "/usr/local/lib/python2.6/dist-packages/selenium/webdriver/remote/webdriver.py", line 443, in quit
self.execute(Command.QUIT)
File "/usr/local/lib/python2.6/dist-packages/selenium/webdriver/remote/webdriver.py", line 151, in execute
response = self.command_executor.execute(driver_command, params)
File "/usr/local/lib/python2.6/dist-packages/selenium/webdriver/remote/remote_connection.py", line 280, in execute
return self._request(url, method=command_info[0], data=data)
File "/usr/local/lib/python2.6/dist-packages/selenium/webdriver/remote/remote_connection.py", line 321, in _request
response = opener.open(request)
File "/usr/lib/python2.6/urllib2.py", line 391, in open
response = self._open(req, data)
File "/usr/lib/python2.6/urllib2.py", line 409, in _open
'_open', req)
File "/usr/lib/python2.6/urllib2.py", line 369, in _call_chain
result = func(*args)
File "/usr/lib/python2.6/urllib2.py", line 1161, in http_open
return self.do_open(httplib.HTTPConnection, req)
File "/usr/lib/python2.6/urllib2.py", line 1136, in do_open
raise URLError(err)
urllib2.URLError: <urlopen error [Errno 111] Connection refused>
Any ideas why this might be the case? Any best practice solutions for overcoming?
I'm thinking of occasionally testing for liveness by driver.current_url
in a try block, and if it throws an exception, then setting the driver to None
, and then re-instantiating it... but it's an ugly hack and I don't understand why it's needed.
After endless struggles with selenium drivers and FF extensions breaking up. I've removed it completely.
I use http://www.phantomjs.org/ which is headless JS lib. Works like charm. (and I you want see the page, you can always make screen-shoot )
I mainly work in ruby so: have replace capybara-webkit with poltergeist (which is just a js_driver for capybara)
I'm quite sure there will be similar solution. Maybe this not answer your question but it will provide with a diffrent look about js testing.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With