Phantomjs 为什么赢了';CasperJS在点击链接后是否接受重定向请求?
我遇到了更多的Casper问题,这次我告诉Casper单击一个href,它将重定向到一个页面,该页面将重定向到twitter应用程序验证页面:Phantomjs 为什么赢了';CasperJS在点击链接后是否接受重定向请求?,phantomjs,casperjs,Phantomjs,Casperjs,我遇到了更多的Casper问题,这次我告诉Casper单击一个href,它将重定向到一个页面,该页面将重定向到twitter应用程序验证页面: var casper = require('casper').create({ verbose: false, logLevel: 'debug', waitTimeout: 10000 }); phantom.cookiesEnabled = true; casper.start('http://foo.bar', f
var casper = require('casper').create({
verbose: false,
logLevel: 'debug',
waitTimeout: 10000
});
phantom.cookiesEnabled = true;
casper.start('http://foo.bar', function afterstart() {
if (this.exists('#back-to-top')) {
this.echo('BOOYA! foo.bar is loaded', 'INFO');
} else {
this.echo('Page didnt load, something went all screwy.', 'ERROR');
}
});
casper.then(function signin() {
this.click('a[href="/sys/login"]' );
});
casper.then(function tellsignin() {
if (this.exists('#not-logged-in ')) {
this.echo("I clicked on twitter login button, so now the twitter login page is loaded.", 'INFO');
} else {
this.echo('Twitter login link didnt work, something went wacky');
};
});
当我运行它时,控制台错误输出是这样的,加上一些其他不重要的东西:
Test file: testingtest.js
BOOYA! foo.bar is loaded
Twitter login link didnt work, something went wacky
我试着查找解释,并找到了组线程,但不幸的是,它没有为我的问题提供任何答案。
有人知道Casper没有重定向的可能原因吗?多亏了您的帮助和支持,我已经解决了这个问题,哈哈!发生的情况是,tellsignin函数是在浏览器有时间重定向到twitter应用程序验证页面之前执行的,所以我只是在signin函数中添加了一个this.waitForText(“授权foo bar应用程序使用您的帐户?”)。这个答案帮助我解决了一个类似的问题。发布表单时,我必须等待文本,以便从post“跟随重定向”。