I have tried various methods in casperJS to fill in and submit a form. The code is shown below. Ultimately I am building a robot to automatically check the status of a cargo airwaybills on the IAG Cargo web portal.
Sendkeys will complete the form but I cannot manage to click the SEARCH button.
Using casperJS Form filling methods does not work at all.
Is this an unusual website or am I doing something wrong?
In the code below the program appears to fail on line
this.clickLabel('SEARCH', 'button');
and the subsequent code does not run.
(I have used an dummy airwaybill number in this example so the final page will show 'Airwaybill not found')
var casper = require('casper').create();
var x = require('casper').selectXPath;
phantom.cookiesEnabled = true;
casper.userAgent('Mozilla/4.0 (compatable; MSIE 6.0; Windows NT 5.1)');
casper.start('https://www.iagcargo.com/iagcargo/portlet/en/html/601/main/search');
casper.waitForSelector("#awb_cia", function() {
this.echo('Selector found');
casper.capture('iag_start.png');
this.sendKeys('#awb_cia','125');
this.sendKeys('#awb_cod','12345675');
});
casper.then(function step2() {
this.clickLabel('SEARCH', 'button');
this.echo('this is step 2');
casper.capture('iag_end.png');
});
require('utils').dump(casper.steps.map(function(step) {
return step.toString();
}));
casper.run();