0

Suppose I have this (fake) JavaScript code:

asynchronousOperation.addEventListener("completed", 
    function (event) {
        if (event.property == "required value") tell Selenium we are good;
        else tell Selenium the test failed;
    });
asynchronousOperation.run();

I'm using Python for writing tests, but I think I'd find a way to adapt the code if it is in some other language.

The best I could manage so far is to write the result somewhere in the page and then check that place using timer. But this sounds like it could be done better.

4

1 回答 1

1

You're on exactly the right track. Adam Goucher calls this type of mechanism a "JavaScript latch", and it's exactly the kind of construct you want to use. Typically, you'd want to use it with the WebDriverWait construct, which should be available in most language bindings, including Python. WebDriverWait establishes a timeout, but polls for the condition you want, returning as soon as the condition is met or the timeout is reached. In this case, the condition would be the JavaScript variable on the page having the appropriate value.

于 2013-06-25T17:18:18.327 回答