PhantomJS无法访问已删除QObject的成员“评估”
PhantomJS cannot access member 'evaluate' of deleted QObject
function checkMessages(user, password, callback) {
var page = require('webpage').create();
page.open('http://mywebpage.com', function (status) {
if (status === 'fail') {
console.log(user + ': ?');
} else {
page.evaluate(function (user, password) {
document.querySelector('input[name=username]').value = user;
document.querySelector('input[name=password]').value = password;
document.querySelector('button[name=yt0]').click();
}, user, password);
waitFor(function() {
return page.evaluate(function() {
var el = document.getElementById('fancybox-wrap');
if (typeof(el) != 'undefined' && el != null) {
return true;
}
return false;
});
}, function() {
var messageCount = page.evaluate(function() {
var el = document.querySelector('span[class=unread-number]');
if (typeof(el) != 'undefined' && el != null) {
return el.innerText;
}
return 0;
});
console.log(messageCount);
});
}
page.close();
callback.apply();
});
}
出于某种原因,我就是无法让它工作。PhantomJS抱怨:"错误:无法访问已删除QObject的成员'评估'"。是因为我有多个页面评估吗?
PhantomJS是异步的。在这种情况下,waitFor()
是异步的,因此您需要在完成page
后关闭它。你需要搬家
page.close();
callback.apply();
进入将要执行的最后一个函数,即waitFor()
的回调。您可能希望稍微更改waitFor
,以便在达到超时时有另一个回调,即错误分支,它也需要关闭页面和回调:
function waitFor(testFx, onReady, timeOutMillis) {
var maxtimeOutMillis = timeOutMillis ? timeOutMillis : 3000,
start = new Date().getTime(),
condition = false,
interval = setInterval(function() {
if ( (new Date().getTime() - start < maxtimeOutMillis) && !condition ) {
condition = testFx();
} else {
var error = null;
if(!condition) {
error = "'waitFor()' timeout";
console.log(error);
} else {
console.log("'waitFor()' finished in " + (new Date().getTime() - start) + "ms.");
clearInterval(interval);
}
onReady(error);
}
}, 250);
};
相关文章:
- 使用正则表达式评估电子邮件地址时出现性能问题
- 更新成员数据模型中的记录列表
- Web应用程序,将成员状态更新为其他成员
- 如何检查链接是否有文本,并根据文本值评估条件-Jquery/JS
- 如何在 JavaScript 中“获取”成员变量
- 使用私有成员创建JavaScript类
- 为什么在这种情况下,“This”确实充当javascript函数中的私有成员
- 类型错误'未定义'不是对象(正在评估'navigator.connection.type'
- 下载javascript文件,但不要立即对其进行评估
- Typescript模块没有导出的成员-react
- 在WebView iOS中评估Javascript
- 用javascript在html显示列表中显示新成员
- TypeError:undefined不是对象(正在评估'newWindow.focus')
- 为什么可以't我使用成员方法初始化一个实例
- r.js评估'text'插件,尽管在'stubModules'参数
- 如何将从XML读取的值存储到本地对象's成员使用.get()函数
- 避免重新评估和动态卸载用“require”调用的对象
- 删除评估值Javascript时的错误
- 咖啡脚本意外的条件评估
- PhantomJS无法访问已删除QObject的成员“评估”