Casperjs Parse Next Page After Button Click
I use casperjs for grab some test. Algorithm is open URL parse page, click button for load next page. How to grab next pages until test is complete. All question get random and I d
Solution 1:
EDIT: You need to nest the steps for the following pages, because on every page you evaluate if it is necessary to go further. Also you should check the URL after you submitted the form.
functionanswer() {
var currentUrl = this.getCurrentUrl(),
startIdPos = currentUrl.indexOf('=') + 1,
questionId = currentUrl.slice(startIdPos),
content = $(this.getHTML()),
answers = [],
question,
startCorrectAnswerPos = content.find('script:nth-child(2)').html().indexOf('var bc='),
correctAnswer = content.find('script:nth-child(2)').html().slice(startCorrectAnswerPos + 8, startCorrectAnswerPos + 9);
question = content.find('table.quizz p.qw').html();
console.log(">>>>>>" + this.getCurrentUrl());
if (question) {
this.then(function(){
this.fill('form', {
'answer': correctAnswer
}, true);
});
this.then(answer);
}
};
casper.then(answer);
Exchange this code for your casper.then
block.
Previous Answer: I don't know what kind of button/link #training
is, but it may be that you need to wait for the change in the page to occur. You could use the casper.waitForSelector
function.
Also I'm not sure why you write
this.evaluate(function () {
$('input[type="submit"]:first').click();
});
and not simply this.click('input[type="submit"]:first');
.
Post a Comment for "Casperjs Parse Next Page After Button Click"