Using ExecuteAsyncScript - WebDriverTimeoutException and not seeing the arguments

449 views
Skip to first unread message

gerrald...@gmail.com

unread,
Feb 23, 2016, 8:43:54 PM2/23/16
to Selenium Users
Hello,
I'm new to webdriver so the question might already be answered but I've not found it here

I need help in understanding usage of ExecuteAsyncScript. Currently the simple test with it gets WebDriverTimeoutException and argument is undefined

IJavaScriptExecutor js = Driver as IJavaScriptExecutor;
Driver.Manage().Timeouts().SetScriptTimeout(TimeSpan.FromSeconds(20));

js
.ExecuteAsyncScript(
               
"console.log('Starting'); setTimeout( function() { console.log('From timeout: '+ document.URL + arguments[arguments.length - 1]) }, 600); console.log('After .....'); ", 10);          


Thanks

Mark Collin

unread,
Feb 24, 2016, 3:08:31 AM2/24/16
to Selenium Users
The JavaScript you are executing needs to return a callback (See https://developer.mozilla.org/en-US/docs/Mozilla/js-ctypes/Using_js-ctypes/Declaring_and_Using_Callbacks).

Selenium will wait for up to the ScriptTimeout time for the JavaScript you have executed to make a callback, if it doesn't detect a callback it will time out.

David

unread,
Feb 24, 2016, 12:34:09 PM2/24/16
to Selenium Users
I don't use executeAsyncScript() myself, but from looking at the OP's post and Mark's response, it would seem the OP is attempting functionality similar to example #1 found under 


e.g. use of setTimeout(), although the OP's implementation might not be implemented correctly.

Mark, any tips for the OP in terms of reworking their setTimeout() implementation to be like the Selenium example? I assume they probably have to wrap the before & after console logs along with the setTimeout call and insert a callback somewhere in there.

Mark Collin

unread,
Feb 24, 2016, 4:17:20 PM2/24/16
to Selenium Users
I would have called Example one a synchronous example because the code isn't going to return until the timeout has completed, I also don't see an explicit callback  (I am not a JavaScript developer though, so there may be something about setTimeout I'm unaware of).

The other examples explicitly define a callback.
Reply all
Reply to author
Forward
0 new messages