I am trying to fill this form using CasperJS. I would like to enter the email and click Unlock this review.
Checking the code using the Inspect Element on Chrome I get the following:
<input id="email" type="text" class="emailAddr focusClear" value="Enter your email address" defaultvalue="Enter your email address" onblur="return ta.call('ta.common.search.defaultOnBlur', event);" onkeydown="return ta.util.keys.onEnterKeyClickSibling(event, '.submitBtn');" onfocus="ta.trackEventOnPage('overlay_registration_email_only', 'focused', '', '39415', false); return ta.call('ta.common.search.clearOnFocus', event);">
<div class="submitBtn rndBtn rndBtnGreen rndBtnLarge taLnk" onclick="ta.servlet.OverlayRegistration.submitEmailOnlySignup(event, ta.id('emailOnlySignup'), oreg_options);">Unlock this review</div>
I don't have a lot of experience with CasperJS, the code I am trying to use to submit this form is the following:
this.sendKeys('input[id="email"]', 'xxx@whatever');
I think I have a problem with the selector but I am not sure. This is the URL I am checking, and you get this form when you click 'More' in a review when you are not logged in.
This is the full code that I am using:
var casper = require("casper").create({
pageSettings: {
userAgent: "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.8; rv:23.0) Gecko/20130404 Firefox/23.0"
}
});
var url = 'http://www.tripadvisor.com/Restaurant_Review-g187497-d782630-Reviews-Restaurante_El_Mussol-Barcelona_Catalonia.html';
casper.start(url, function() {
this.echo('ok');
this.click("span.taLnk.hvrIE6.tr299457563.moreLink.ulBlueLinks");
this.echo('ok2');
this.capture('test-screen1.png');
}).wait(15000).then(function() {
this.echo('ok3');
this.capture('test-screen2.png');
/**this.fill('input.emailAddr', {
'email': 'xxx@whatever'
});*/
this.echo('ok4');
this.sendKeys('input[value="email"]', 'xxx@whatever');
this.echo('ok5');
this.capture('test-screen3.png');
}).wait(5000).then(function() {
this.echo('ok5');
this.capture('test-screen4.png');
});
/**fs.write(path,content,'w')**/
casper.run();
I never reach 'ok5' and the form is not filled. I suspect it is in the CSS selector that I am doing something wrong.