How to get Javascript asynchronous responses from Selenium Webdriver

We have added an asynchronous javascript call to our site. I am trying to get Selenium Webdriver to wait for a response from a call.

The listener is as follows:

$(document).on("application:subapp:rendered", function(){console.log("foo");});

My webdriver code (python):

driver.set_script_timeout(30)
response =  driver.execute_async_script("$(document).on(\"application:subapp:rendered\", function(){return \"foo\";});"

Next, I launched the page to make "foo" return

however this is my answer ...

TimeoutException: Message: asynchronous script timeout: the result was not received after 30 seconds (Session information: chrome = 41.0.2272.118) (Driver information: chromedriver = 2.11.298604 (75ea2fdb5c87f133a8e1b8da16f6091fb7d532 1e), platform = Windows NT 6.164_6464_64

+4
source share
2

execute_async_script, Selenium JavaScript , , , , script execute_async_script, arguments[0] JavaScript. , , execute_async_script:

response = driver.execute_async_script("""
    var done = arguments[0];
    $(document).one("application:subapp:rendered", 
        function(){
           done("foo");
    });
""")

done. , . , , response, done("foo").

, .one(), .on(). , Selenium ( , 2.45) , execute_async_script, "", , , JavaScript , , . execute_async_script, execute_async_script "foo". . .

+7

arguments[0] :

driver.execute_async_script("""
    $(document).on('application:subapp:rendered', arguments[0]);
""")

. ( ):

+2

All Articles