Selenium freezes after waiting for an element (Python)

we use the Python Selenium and django-selenium (SeleniumTestCase) bindings to run Selenium tests. Our test page has HTML elements that are created after some delay of seconds. Therefore, we want to wait for them and continue the test. The wait works, but each command fails after calling the wait:

class SomeTestCase(SeleniumTestCase): def test_something(self): ... (some testing code that works) self.driver.wait_element_present('span.available') # this works self.driver.wait_element_present('span.connected') # this works, too self.driver.find_element_by_css_selector('body') # this fails 

I debugged the selenium code and found out that "find_element_by_css_selector" internally sends an HTTP request to the selenium server (as in every command "check if xxx is there"):

 http://127.0.0.1:42735/hub/session/<session-id>/element 

But this request returns with status code 500 and this response text:

 { "status": 13, "value": { "message": "JSON.parse: unexpected non-digit", "stackTrace": [ { "methodName": "Dispatcher.executeAs/<", "fileName": "file:///tmp/tmpnUT34U/extensions/ fxdriver@googlecode.com /components/driver_component.js", "lineNumber": 7354 }, { "methodName": "Resource.prototype.handle", "fileName": "file:///tmp/tmpnUT34U/extensions/ fxdriver@googlecode.com /components/driver_component.js", "lineNumber": 7516 }, { "methodName": "Dispatcher.prototype.dispatch", "fileName": "file:///tmp/tmpnUT34U/extensions/ fxdriver@googlecode.com /components/driver_component.js", "lineNumber": 7463 }, { "methodName": "WebDriverServer/<.handle", "fileName": "file:///tmp/tmpnUT34U/extensions/ fxdriver@googlecode.com /components/driver_component.js", "lineNumber": 10152 }, { "fileName": "file:///tmp/tmpnUT34U/extensions/ fxdriver@googlecode.com /components/httpd.js", "lineNumber": 1935 }, { "methodName": "ServerHandler.prototype.handleResponse", "fileName": "file:///tmp/tmpnUT34U/extensions/ fxdriver@googlecode.com /components/httpd.js", "lineNumber": 2261 }, { "methodName": "Connection.prototype.process", "fileName": "file:///tmp/tmpnUT34U/extensions/ fxdriver@googlecode.com /components/httpd.js", "lineNumber": 1168 }, { "methodName": "RequestReader.prototype._handleResponse", "fileName": "file:///tmp/tmpnUT34U/extensions/ fxdriver@googlecode.com /components/httpd.js", "lineNumber": 1616 }, { "methodName": "RequestReader.prototype._processBody", "fileName": "file:///tmp/tmpnUT34U/extensions/ fxdriver@googlecode.com /components/httpd.js", "lineNumber": 1464 }, { "methodName": "RequestReader.prototype.onInputStreamReady", "fileName": "file:///tmp/tmpnUT34U/extensions/ fxdriver@googlecode.com /components/httpd.js", "lineNumber": 1333 } ] } } 

As a result, all test runs are blocked and interrupted after a default timeout. According to https://code.google.com/p/selenium/wiki/JsonWireProtocol status 13 means "UnknownError", which does not make things more clear; -)

Has anyone discovered this too? Is there any way to solve this? I don’t know exactly what the reason may be, our page structure is pure html code. Thanks for any suggestions!

+4
source share
1 answer

Later side but -

wait_element_present is not a binding to Selenium. This is from a custom class from another MyDriver library https://django-selenium.readthedocs.org/en/latest/#mydriver-class

Selenium's explicit expectations are more than a simple function: http://selenium-python.readthedocs.org/waits.html#explicit-waits

find_element_by_css_selector is the Selenium binding for webdriver, and MyDriver does not have a method with this name.

To use custom classes to run the Selenium web editor, you need to use the methods that it provides (or write yourself). In this case, MyDriver has a find method that takes a CSS selector as an argument and returns an element that does what you wanted to do with find_element_by_css_selector . https://github.com/dragoon/django-selenium/blob/master/django_selenium/testcases.py

0
source

Source: https://habr.com/ru/post/1496734/


All Articles