florentbr/SeleniumBasic

ExecuteScript wait for full JS to execute

Opened this issue · 2 comments

Trying to Execute multiple line js scripts in 1 call, but the function of ExecuteScript right after the first and not waiting till the end of the full code.

using a js sync waiting function to demonstrate it, I have a js function syncwait(ms), which halts js for a given time.

Here is example code

retval= driver.ExecuteScript("syncwait(3000); alert('after first wait'); syncwait(3000); alert('after 2nd wait');")

messagebox(retval)

My message box will show right after the first syncwait() is completed, and 3 seconds later I'll get the 2nd alert, is there anyway to make the ExecuteScript wait for full execution?

this is my syncwait code

function syncwait(ms) {
    var start = Date.now(),
        now = start;
    while (now - start < ms) {
      now = Date.now();
    }
}

欢迎交流SeleniumBasic ,QQ群:点击链接加入群聊【天天ASP家园】:https://jq.qq.com/?_wv=1027&k=mBY9APOM