2

I'm a newcomer to CasperJS and after a couple hours I can login and navigate a few webpages with it, but I'm stumped by the alert message on this website: https://www.macysliquidation.com/

I need to get rid of the alert so I can login.

My simple (non-working) code is:

var casper = require('casper').create();
casper.userAgent('Mozilla/12.0 (compatible; MSIE 6.0; Windows NT 5.1)');

casper.on('remote.alert', function(message) {
    this.echo('alert message: ' + message);
    // how do i get rid of the popup??
    this.thenClick();
});

casper.start('https://www.macysliquidation.com/');


casper.then(function() {
    // login here
    this.sendKeys('#txtUsername','username');
    this.sendKeys('#txtPassword','password');
    this.thenClick('#btnLogin');
 });

casper.run(function() {
    // see what went on
    this.capture('page.png');
    this.echo('done').exit();
});

Till the time the alert is clicked away, the login controls aren't visible/available. So the above js returns

Cannot get informations from #txtUsername: element not found

Artjom B.
  • 61,146
  • 24
  • 125
  • 222
erohtar
  • 33
  • 7
  • This might be relevant: there's a new command waitForAlert() in CasperJS version 1.1-beta4, but I couldn't try it as the latest version available on their website is version 1.1-beta3. – erohtar Feb 08 '15 at 02:57
  • Actually till the time the alert is clicked away, the login controls aren't visible/available. So the above js returns 'Cannot get informations from #txtUsername: element not found'. (also sorry for slightly late reply, any way StackOverflow can email me for any comments to my question?) – erohtar Feb 09 '15 at 04:14

1 Answers1

3

As you already noticed the function capser.waitForAlert() is available since version 1.1-beta4. You can copy the function from the code if you don't have the time to upgrade:

casper.waitForAlert = function(then, onTimeout, timeout) {
    ...
};

Problem:

Alerts and confirm just happen and they don't stop the execution in PhantomJS and CasperJS. They are also not part of the page and cannot be clicked on.

If you would register to the error events (resource.error and page.error and remote.message is always a good idea) in CasperJS, you would have seen that a specific resource error was thrown:

{"errorCode":6,"errorString":"SSL handshake failed","id":1,"url":"https://www.macysliquidation.com/"}

If you would have checked the status of the page, you would have seen that it wasn't loaded.

Solution:

Run CasperJS with --ignore-ssl-errors=true and depending on your PhantomJS version with --ssl-protocol=tlsv1. More information here.

Community
  • 1
  • 1
Artjom B.
  • 61,146
  • 24
  • 125
  • 222
  • '--ignore-ssl-errors=true' worked PERFECTLY! Thank you very much kind sir for the explanation of the issue, and the solution (and even for paraphrasing my query so it makes more sense). And I'm sorry for the (very) delayed reply - I never got a notification from StackExchange about your response, and thought the query was not answered. Thanks again. – erohtar Feb 24 '15 at 21:32