我正在尝试使用casper登录Facebook。我的程序如下:
var casper=require("casper").create({
clientScripts:["C:\Users\HP\Desktop\Python\jsfiles\jquery.min.js"],
verbose:true,
logLevel: 'debug'
});
var x =require('casper').selectXPath;
casper.userAgent('Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/43.0.2357.130 Safari/537.36');
phantom.cookiesEnabled=true;
var fs=require('fs');
var cookies=JSON.stringify(phantom.cookies);
fs.write('cookies.txt',cookies,644);
casper.start("https://www.facebook.com",function(){
this.echo(this.getTitle());
}).viewport(1200,1000);
casper.wait(5000,function(){
casper.capture('test1.png')
});
casper.waitForSelector(x('//*[@id="pass"]'),function(){
this.thenEvaluate(function(){
$('#email').val("");
$('#pass').val(" ");
});
});
casper.wait(5000,function(){
casper.capture('test2.png')
});
casper.then(function(){
casper.click(x('//*[@id="loginbutton"]'));
});
casper.wait(5000,function(){
casper.capture('test3.png')
});
casper.run();上面的程序完全返回,但是test2.png没有在email和password文本框中显示任何数据。此外,test3.png返回“输入有效的电子邮件”。
我哪里错了?
发布于 2015-11-17 23:19:59
这是由于javascript中的错误!
$('#email').val("");将id为email的字段设置为空字符串!
如果想要检索jQuery-Field的值,可以这样做:
$('#email').val();
如果您在使用jQuery时遇到更多问题,This可能会帮助您
https://stackoverflow.com/questions/31413397
复制相似问题