0
为什么在'clickOldShares'中等待不起作用?即使我在里面评价,等待也不起作用。我相信这是一个带有参考的小细节,但我现在没有想法。在CasperJS你如何做等待工作?
function clickOldShares(){
console.log("Waiting for Old Shares");
element = document.querySelector("#pagelet_scrolling_pager > div > div > a");
console.log("ELEMENT: " + element);
if(element){
console.log('click and waiting...');
element.click();
console.log('clicked!'+ element);
//THIS WAIT IS NOT WORKING!!!! I DON'T KNOW WHY!!!!
this.wait(2000,clickOldShares);
}
else {
console.log("done!");
}
return element;
};
//Initializing Casper
casper.start('https://www.facebook.com/', function() {
console.log("Entering on Facebook");
});
//Remote Message Handler - now I can see what happen inside evaluates
casper.on('remote.message', function(msg) {
this.echo(msg);
})
//Facebook login
casper.then(function(){
console.log("Login using username and password");
this.evaluate(function(){
document.getElementById("email").value = '[email protected]';
document.getElementById("pass").value = 'somepass';
document.getElementById("login_form").submit();
})
if(this.exists('#u_0_2 > div:nth-child(1) > div:nth-child(1) > div > a > span')){
console.log("Login ok!");
}
else {
console.log("Login not ok!");
casper.exit();
}
});
casper.thenOpen("https://www.facebook.com/shares/view?id=1063249230414580" ,function(){
console.log("Open post with object-id");
});
casper.thenClick("#pagelet_scrolling_pager > div > div > a",function(){
this.wait(2000,function(){ this.evaluate(clickOldShares)});
});
我太亲近了!但是,多亏了你,我更了解了JavaScript中的'范围游戏'。非常感谢! 图像不好,因为有很多数据。但是我已经要求getHTML来查看,并且所有内容都在那里! 我欠你一杯啤酒! 再次感谢! :D –
'!!元素'呢?我不知道这在JavaScript中。有关于它的文档?说到这一点,我可以问你一篇关于Javascript文章的建议吗? –
[这个符号在JavaScript中的含义是什么?](http://stackoverflow.com/q/9549780/1816580)参考问题链接到[什么是! (不是)运营商在JavaScript?](http://stackoverflow.com/q/784929/1816580),这是需要在这里,因为DOM节点不能被传递出的页面上下文。这个限制是PhantomJS的一个特点,并不是由于JavaScript。 –