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.
WebDriverWaitconstruct, which should be available in most language bindings, including Python. This 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.