我无法捕获网页的所有内容。使用常规浏览器登录Outlook.com后,它将在右侧显示收件箱消息:
但是,当我使用CasperJS时,它只是空白。有人有什么主意吗?
我在脚本中包含一个临时登录ID,如果可以的话,您可以对其进行测试,谢谢。
这是脚本:
var casper = require('casper').create({
verbose: true,
logLevel: "info",
viewportSize: {width: 1280,height: 720},
pageSettings: {userAgent: "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_2) AppleWebKit/537.11 (KHTML, like Gecko) Chrome/23.0.1271.97 Safari/537.11"}
});
casper.start('http://www.hotmail.com').then(function () {
console.log('got here');
});
casper.wait(500, function () {
console.log('wait');
});
casper.then(function(){
this.sendKeys("[name='loginfmt']", 'peterwhite12345678@outlook.com');
this.sendKeys("[name='passwd']", '12345678peterwhite');
this.click("[type='submit']");
console.log('entering log in information');
});
casper.wait(5000, function () {
console.log('wait');
});
casper.then(function (){
console.log('printscreen');
casper.capture('there_is_nothing_by_the_right_side.png')
});
casper.run();
我也尝试过类似
casperjs --ssl-protocol=any outlook.js
是否应该添加任何路径/插件来支持此CasperJS?
最佳答案
试试下面的代码。您需要给/提供足够的时间来打开网页
var casper = require('casper').create({
// verbose: true,
// logLevel: "info",
viewportSize: {width: 1280, height: 720},
pageSettings: {userAgent: "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_2) AppleWebKit/537.11 (KHTML, like Gecko) Chrome/23.0.1271.97 Safari/537.11"}
});
casper.start('http://www.hotmail.com').then(function () {
console.log('got here');
});
casper.wait(1000, function () {
console.log('wait');
});
casper.then(function () {
this.sendKeys("[name='loginfmt']", 'peterwhite12345678@outlook.com');
this.sendKeys("[name='passwd']", '12345678peterwhite');
this.click("[type='submit']");
console.log('entering log in information');
});
casper.wait(20000, function () {
this.waitForSelector('#O365_MainLink_Settings', function () {
this.test.assertExists('#O365_Lync_ButtonID', 'Lync icon is visble, hence confirmed that page opened completely');
});
});
casper.waitForSelector(('._rp_52 > div:nth-child(4)'), function () {
if (this.visible("button._rp_o1:nth-child(2)")) {
console.log("Here we go, Right side is visible");
casper.capture('there is something.png');
}
else {
console.log("Nope")
}
});
casper.run();