url = "https://example.com/";
casper.start(url, function () {
this.echo('url: ' + url);
this.echo('myCloud requested...');
this.echo('Page title: ' + this.getTitle());
});
casper.then(function () {
this.echo('Clicking submit button...');
this.click('input#SubmitButton');
...
当我在普通浏览器中请求portalUrl(“https://example.com/”)时,它会重定向到ADFS登录页面“ADFSloginUrl”,但是使用CasperJS它无法访问ADFS的登录页面。
在上面的代码中请求的页面未加载。所以'this.getTitle()'为空,无法访问CasperJS的提交按钮。
访问提交按钮时,会出现以下错误:
“消息:CasperError:无法在不存在的选择器上调度mousedown事件:input#SubmitButton”
这是否与casper.start
有关?
答案 0 :(得分:1)
- ssl-protocol = any 为我解决了这个问题。 casperjs --ssl-protocol =任何yourcode.js
感谢您的所有答案,他们真的很有帮助
答案 1 :(得分:0)
如何使用waitFor
:
url = "https://example.com/";
casper.start(url, function () {
this.echo('url: ' + url);
});
casper.waitFor('input#SubmitButton', function () {
this.echo('Page title: ' + this.getTitle());
this.echo('Clicking submit button...');
this.click('input#SubmitButton');
}, function onTimeout(){
this.echo("The submit button did not appear within 15 seconds...");
}, 15000 ); //15 second timeout
如果这确实有效,则可能表明重定向发生在JavaScript而不是HTTP级别。 (无论如何,这是一个很好的方法,否则微妙的计时错误可能会蔓延到您的代码中。)
或者,看看this bug report,它指出PhantomJS和SlimerJS之间的行为有点不同。