waitForSelector timeout???

7,192 views
Skip to first unread message

Sven

unread,
Sep 4, 2012, 3:27:17 AM9/4/12
to casp...@googlegroups.com
Good day to all,

I am really new to CasperJS. Very cool project! Love it!

I am having problems with waitForSelector()?
Maybe I misunderstand but I am using this to basically halt the script until the selector becomes available.

No lets say there is a anchor link at bottom of page with a href='www.example.com/logout.html'

Then this is my code:

token_logout = 'www.example.com/logout.html';
casper.waitForSelector('a[href= "' + token_keywpage + '"]', function eWaitForKwPageLoad() {
this.echo('Can Log Out Now \n\n\n');
});

Please assist :)

Sven

unread,
Sep 4, 2012, 3:53:19 AM9/4/12
to casp...@googlegroups.com
Maybe it could be because it never hits the page I am hoping it  does.
In that case ---> How do visually see which pages gets loaded?

I have tried to make screen shots for debugging assistance by using capture() but that fails with an error:

FAIL CasperError: clipRect must be a valid ClipRect object.
#    type: uncaughtError
#    error: "CasperError: clipRect must be a valid ClipRect object."
CasperError: clipRect must be a valid ClipRect object.

Roberto Rodrigues

unread,
Sep 4, 2012, 8:44:55 PM9/4/12
to casp...@googlegroups.com
Try enabling the debug mode that will show which page is loaded.
And to take a picture of the page use:

casper.page.render ('page.png');

Sven

unread,
Sep 10, 2012, 3:22:13 PM9/10/12
to casp...@googlegroups.com
Thanks for the reply. Why do I get the following error:

FAIL CasperError: clipRect must be a valid ClipRect object.
#    type: uncaughtError
#    error: "CasperError: clipRect must be a valid ClipRect object."
CasperError: clipRect must be a valid ClipRect object.
  F:/Phantomjs:231 in capture
  F:/Phantomjs/test.js:74
  F:/Phantomjs:1051 in runStep
  F:/Phantomjs:323 in checkStep

Sven

unread,
Sep 10, 2012, 3:41:28 PM9/10/12
to casp...@googlegroups.com
Okay despite the error messages - it is at least rendering the screen shot.
I keep on getting:

[error] [phantom] Timeout of 5000ms expired, exiting.

Although I have set timeout values on Casper calls to 200000. Why does my timeout values not apply? Seems like it gets ignored cause it timeout after 5 seconds.
Please advise :)

Sven

unread,
Sep 10, 2012, 4:12:07 PM9/10/12
to casp...@googlegroups.com
Okay let me explain.
I want to wait for a button to load with a class="ABC"

So here is my waitForSelector statement:

var token_button_class = 'ABC';
casper.waitForSelector('input[class="' +  token_button_class + '"]', function eWaitForButton() {
this.echo('Title: ' + this.getTitle() + '\n\n\n');
}, 300000);

Why does this timeout?
The button gets loaded - I know.

Roberto Rodrigues

unread,
Sep 10, 2012, 5:26:54 PM9/10/12
to casp...@googlegroups.com
I do not know why the error, but it seems to be something of phantomjs.
And the timeout is not working because it is in the wrong place, waitForSelector method syntax is as follows:

waitForSelect (selector, then, ontimeout, timeout);

In your example would be something like

var token_button_class = 'ABC';
casper.waitForSelector('input[class="' +  token_button_class + '"]', 
function eWaitForButton() {
this.echo('Title: ' + this.getTitle() + '\n\n\n');
}, function() {
        this.echo("Timeout reached");
        // do something
},
300000);

Sven

unread,
Sep 11, 2012, 7:29:13 AM9/11/12
to casp...@googlegroups.com
Thanks for the reply, but I am missing something.
You say the syntax is: 
"waitForSelect (selector, then, ontimeout, timeout);"

And this is what I've got:
var token_button_class = 'ABC';
casper.waitForSelector(
'input[class="' +  token_button_class + '"]', 

function eWaitForButton() 
{
this.echo('Title: ' + this.getTitle() + '\n\n\n');
}, 

function() 
{
        this.echo("Timeout reached");
        // do something
},

300000);

You would see my syntax is exactly as you suggested...
Or please help me out - what am I missing?
:)

Roberto Rodrigues

unread,
Sep 11, 2012, 6:11:03 PM9/11/12
to casp...@googlegroups.com
Unfortunately I do not know what the problem is.
Try changing the maximum timeout.

var casper = require('casper').create({
    verbose: true,
    logLevel: "debug",
    timeout: 15000 // new maximum timeout
});

See here: http://casperjs.org/api.html#casper on Casper options

Mario Ruiz

unread,
Aug 13, 2014, 3:01:24 PM8/13/14
to casp...@googlegroups.com
Thanks,

 I'm using this option 

   waitTimeout

and is working fine. 

var casper = require('casper').create({
     logLevel: "debug",              
    verbose: true,                  
    waitTimeout: 25000 // new maximum waitTimeout
});

or also 

var casper = require('casper').create();
casper.options.waitTimeout = 1000;
Reply all
Reply to author
Forward
0 new messages