我的casperjs点击在大多数网站上工作正常,但是当我尝试点击reddit上的内容时,它不会点击。
casper.start();
casper.then(function (){
this.open("http://reddit.com");
});
casper.then(function(){
this.sendKeys("[name='user']", 'someusername');
this.sendKeys("[name='passwd']", 'somepassword');
this.click("[id='rem-login-main']");
this.click(x('//*[@id="login_login-main"]/div[3]/button'))
});
casper.run();
sendkeys功能运行良好,但点击功能都不起作用,请帮忙!
答案 0 :(得分:0)
找到以下代码及其工作
casper.test.begin("Opening Reddit page", 1, function suite(test) {
var x = require('casper').selectXPath;//required if we detect an element using xpath
casper.start();
casper.viewport(1024, 768).then(function () {
this.open("http://reddit.com");
this.wait(5000)
});
casper.then(function () {
this.sendKeys("[name='user']", 'username');
this.sendKeys("[name='passwd']", 'password');
this.click("[id='rem-login-main']");
this.click(x(".//*[@id='login_login-main']/div[3]/button"));
});
casper.wait(5000)
casper.then(function () {
this.test.assertExists(x(".//*[@id='header-img']"), "Confirmed that page has successfully loaded");
});
casper.run(function () {
test.done();
});
});