use*_*265 2 node.js selenium-webdriver webdriver-io
我正在尝试使用PhantomJS / Chrome运行webdriverio以加载页面,然后获取窗口对象以与其他脚本一起使用。由于某种原因,我无法获取窗口对象。每当我得到时,我最终都会看到这样的输出:
Title is: XXXXX
{ state: 'pending' }
Run Code Online (Sandbox Code Playgroud)
使用以下脚本:
var webdriverio = require('webdriverio');
var options = {
desiredCapabilities: {
browserName: 'chrome',
logLevel: 'verbose'
}
};
var client = webdriverio.remote(options);
client
.init()
.url('https://xxxx.com')
.waitUntil(function () {
return client.execute(function () {
return Date.now() - window.performance.timing.loadEventEnd > 40000;
}).then(function (result) {
console.log(window);
return window;
});
})
.end();
Run Code Online (Sandbox Code Playgroud)
有谁知道我该如何修复我的代码,以便在页面完全加载后将窗口对象返回到我的NodeJS控制台应用程序?
谢谢!
Window是浏览器DOM中的一个对象,因此仅在'execute'函数内部可用。如果要访问它,可以从“执行”功能将其返回:
return client.execute(function () {
return window;
}).then(function (result) {
console.log(result);
});
Run Code Online (Sandbox Code Playgroud)