Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/41.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/selenium/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Node.js 正在使用Selenium等待JavaScript事件_Node.js_Selenium_Selenium Webdriver_Automation_Browser Automation - Fatal编程技术网

Node.js 正在使用Selenium等待JavaScript事件

Node.js 正在使用Selenium等待JavaScript事件,node.js,selenium,selenium-webdriver,automation,browser-automation,Node.js,Selenium,Selenium Webdriver,Automation,Browser Automation,我正在Selenium(Node.js)之上构建一个自动化框架,包括许多步骤。 每一步都遵循前一步,完成后返回一个承诺(如Selenium的驱动程序返回的承诺。click()等)。 是否可以等待浏览器上触发JavaScript事件?如果是,遵循什么模式?使用.executeAsyncScript等待事件发生: driver.executeAsyncScript(function(callback) { window.addEventListener('message', function o

我正在Selenium(Node.js)之上构建一个自动化框架,包括许多步骤。 每一步都遵循前一步,完成后返回一个承诺(如Selenium的驱动程序返回的承诺。click()等)。
是否可以等待浏览器上触发JavaScript事件?如果是,遵循什么模式?

使用
.executeAsyncScript
等待事件发生:

driver.executeAsyncScript(function(callback) {
  window.addEventListener('message', function onmessage() {
    window.removeEventListener('message', onmessage);
    callback();
  });
});
文件:


您的意思是等待java脚本完全执行并使用selenium返回吗?不,我的意思是:等待JavaScript事件触发。使用driver.executeScript()等待脚本执行非常简单。例如,我想注入window.onmessage=function(){…继续node.js承诺链…}