简体   繁体   中英

how to recover from socket.timeout error is selenium(python)

I am using selenium 2.44 and firefox 34.0, the test is on a site that shows inconsistent behaviour: some page loads result in a socket.timeout error (the firefox loading icon keeps spinning). after this error, any call to the driver object result in a httplib.CannotSendRequest thus I cannot recover from the error and continue the test flow.

according to this: httplib CannotSendRequest error in WSGI

The driver object is probably waiting for the loading process to complete and does not allow access to the object.

the question is how do I recover from this error?

the ideal solution will be closing the window with the problem and continue with the test by loading the next pages. the problem is that I cannot use driver.close() because as describe the driver object is inaccessible. driver.current_url is not accessible as well and thus I cannot find out the current driver test position. the last resort I am thinking about it is storing before every load the last URLs of all the windows handles and as the exception occurs recreate the driver and load all windows(that follows after that window with error).

that certainly is a suboptimal solution but is it unavoidable?

My final solution was as described in the question, I just created a new webdriver instance and continue to load the pages in it. the faulty webdriver window(and sometimes more than one) stays open until the end of the run, but it is ignored. If you have multiple pages you can store the URLs of all the windows(before the driver.get('URL') command and reload them in case this error arises. that is not an optimal solution, but it works.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM