Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Selenium freezes after waiting for element (Python)

we're using the Python bindings of Selenium and django-selenium (SeleniumTestCase) for doing Selenium tests. On our tested page there are HTML elements that are created after some seconds delay. So we want to wait for them and then continue the test. The waiting itself works, but every command after the wait call fails:

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 through the selenium code and found out that the "find_element_by_css_selector" internally posts an HTTP request to the selenium server (as on every "check if xxx is there" command):

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/[email protected]/components/driver_component.js",
                "lineNumber": 7354
            },
            {
                "methodName": "Resource.prototype.handle",
                "fileName": "file:///tmp/tmpnUT34U/extensions/[email protected]/components/driver_component.js",
                "lineNumber": 7516
            },
            {
                "methodName": "Dispatcher.prototype.dispatch",
                "fileName": "file:///tmp/tmpnUT34U/extensions/[email protected]/components/driver_component.js",
                "lineNumber": 7463
            },
            {
                "methodName": "WebDriverServer/<.handle",
                "fileName": "file:///tmp/tmpnUT34U/extensions/[email protected]/components/driver_component.js",
                "lineNumber": 10152
            },
            {
                "fileName": "file:///tmp/tmpnUT34U/extensions/[email protected]/components/httpd.js",
                "lineNumber": 1935
            },
            {
                "methodName": "ServerHandler.prototype.handleResponse",
                "fileName": "file:///tmp/tmpnUT34U/extensions/[email protected]/components/httpd.js",
                "lineNumber": 2261
            },
            {
                "methodName": "Connection.prototype.process",
                "fileName": "file:///tmp/tmpnUT34U/extensions/[email protected]/components/httpd.js",
                "lineNumber": 1168
            },
            {
                "methodName": "RequestReader.prototype._handleResponse",
                "fileName": "file:///tmp/tmpnUT34U/extensions/[email protected]/components/httpd.js",
                "lineNumber": 1616
            },
            {
                "methodName": "RequestReader.prototype._processBody",
                "fileName": "file:///tmp/tmpnUT34U/extensions/[email protected]/components/httpd.js",
                "lineNumber": 1464
            },
            {
                "methodName": "RequestReader.prototype.onInputStreamReady",
                "fileName": "file:///tmp/tmpnUT34U/extensions/[email protected]/components/httpd.js",
                "lineNumber": 1333
            }
        ]
    }
}

As result the whole test run blocks and is aborted after the default timeout. According to https://code.google.com/p/selenium/wiki/JsonWireProtocol the status 13 means "UnknownError" which does not make things more clear ;-)

Has anyone discovered this, too? Is there any way to solve this? I do not really know what the exact cause could be, our page structure is clean html code. Thanks for any suggestions!

like image 884
dArignac Avatar asked Aug 13 '13 08:08

dArignac


1 Answers

Late to the party, but--

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

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

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

To use custom classes to run Selenium webdriver, you'll need to use the methods it provides (or write your own). In this case, MyDriver has a method called find that accepts a CSS selector as an argument and returns the element, which accomplishes what you wanted to do with find_element_by_css_selector. https://github.com/dragoon/django-selenium/blob/master/django_selenium/testcases.py

like image 190
NoSuchElephantException Avatar answered Oct 10 '22 23:10

NoSuchElephantException