Sometimes, in the middle of my script, my webdriver instance just dies!
And from now on, I can not refer to any of his 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 could be so? Any better solutions to overcome?
I am thinking about occasionally testing liveness on driver.current_url in a try block, and if it throws an exception, then installing the driver on None and then re-creating the instance ... but it's an ugly hack, and I donβt understand why it is necessary.