19

I have a problem with https page. Page is completly ok, it exist but phantomjs tell me something else: 'loading resource failed with status fail'. I read about it for a while and for now i know it's phantomjs bug and the solution to this problem is:

--ignore-ssl-errors=true

So I know solution, but don't how to use it. How can I pass this to phantomjs from casper? Where should I do that ?

EDIT:

Entire code:

var casper = require('casper').create({
        verbose: true,
        logLevel: 'warning',
        pageSettings: { javascriptEnabled:  true },
        viewportSize: {width: 1024, height: 768}
    });

    var url = 'http://us3.php.net/manual/en/function.explode.php',
        xp = require('casper').selectXPath;

    // ### AKCJE PODSTAWOWE ###
        casper.start(url);

            casper.userAgent('Mozilla/5.0 (Windows NT 6.1; WOW64; rv:25.0) Gecko/20100101 Firefox/25.0');

            casper.then(function(){this.captureSelector('logi/img1.png', 'body');});

            casper.then(function(){ this.sendKeys(xp('/html/body/nav/div/div/div/form/span/input[2]'),'test18');});

            casper.then(function(){this.captureSelector('logi/img2.png', 'body');})

            casper.thenClick(xp('/html/body/div[3]/div/section/div/div[2]/a[1]'));

            casper.wait(2000);
            casper.then(function(){this.captureSelector('logi/img3.png', 'body');})

            casper.run(function(){ this.exit(); }); 
Piotr Wu
  • 1,362
  • 3
  • 14
  • 31

2 Answers2

19

As per https://casperjs.readthedocs.org/en/latest/cli.html#casperjs-native-options

Last but not least, you can still use all PhantomJS standard CLI options as you would do with any other phantomjs script:

$ casperjs --web-security=no --cookies-file=/tmp/mycookies.txt myscript.js

So, I guess, it would be

casperjs --ignore-ssl-errors=true yourjsapp.js 
sudipto
  • 2,472
  • 1
  • 17
  • 21
  • 6
    I wonder if I'm able to ignore ssl programmatically within the yourjsapp.js if I want ignore ssl by default, like options? e.g. `casper({ignore-ssl: true});` Couldn't find any documentation about this. – Bobby Jun 16 '14 at 17:40
  • That's exactly what I'm after just now, @Bobby. Did you ever find out? – josh Nov 24 '14 at 15:23
  • 1
    @josh, since I'm using Casper along with Node and Gulp, I end up using [gulp-shell](https://www.npmjs.org/package/gulp-shell) to make an alias for that. e.g. I register this command `casperjs --ignore-ssl-errors=true yourjsapp.js` into `gulp casper`. – Bobby Nov 25 '14 at 05:39
  • 1
    aha cool. I actually found this eysterday which might work from inside of a js file (though I've gone a similar route to yourself). Here in case it helps anyone: https://github.com/ariya/phantomjs/issues/11775 – josh Nov 25 '14 at 13:36
  • Want to set ssl-protocol to tlsv1 Working for phantomjs but not for casperjs phantomjs --ssl-protocol=tlsv1 sslCheck.js casperjs --ssl-protocol=tlsv1 test MQR15BVT_LoadTesting.js Am I doing anything wrong ! – Surender Singh Malik Mar 11 '15 at 19:04
2

Was having the same issue with a site that was previously working but then suddenly stopped working with the "Loading resource failed with status=fail:" message.

I hadn't changed versions of anything nor my script so something must have changed on the server side. Ultimately, the fix for me was to set the following option:

--ssl-protocol=tlsv1

This link was useful in giving some different options to try: https://github.com/n1k0/casperjs/issues/49

Other suggestions on the page were:

--ignore-ssl-errors=true
--ssl-protocol=any
james
  • 618
  • 7
  • 9
  • The better question for this answer would be [this one](http://stackoverflow.com/questions/26415188/casperjs-phantomjs-doesnt-load-https-page) (I answered it already). – Artjom B. Oct 27 '14 at 22:32
  • Thanks, Artjom. That question didn't have my particular error and I wasn't sure of the exact cause. I added a comment with the error I was getting so maybe others will pick that question up in a search. – james Oct 29 '14 at 15:47
  • I'm using the phantomcss grunt plugin. Within a plugin's js file there is a line ` casper = require('casper').create({` where options get passed. Is it possible to use the `ssl-protocol=tlsv1` there? If it is - how? – user2718671 Dec 14 '16 at 11:11