CasperJS, the test page doesn't load totally

I'm new to casperjs and I want test the drop-down list from this page : http://www.spareka.fr/pieces_detachees_accessoires_electromenager

The element is at the top right of page ("Quel type d'appareil?"). So, I run this script :

...
this.fillSelectors("form#search_form_4", {
  ...
  ...
});
...

But my shell display this error : "Form not found" I checked, and the selector is good. So, I capture the page in the beginning of my script and I notice my page haven't load every elements (the form with id "search_form_4" is not visible).

I thinked my page need time to load, so I use this.wait like this :

...
this.capture("screen01.png");
this.wait(100000, function(){
  this.capture("screen02.pbg");
});
...

But in the end, the screen01 show the same content as the screen02. I don't understand why the page doesn't load totally when I use CasperJS :/ Can you help me ?

Edit : My logs :

asus4@asus4-VirtualBox ~/Bureau/tests casper/test $ sudo casperjs script_test.js
[info] [phantom] Starting...
[info] [phantom] Running suite: 2 steps
[debug] [phantom] opening url: http://www.spareka.fr/piece_detachees_accessoires_electromenager, HTTP GET
[debug] [phantom] Navigation requested: url=http://www.spareka.fr/piece_detachees_accessoires_electromenager, type=Other, willNavigate=true, isMainFrame=true
[debug] [phantom] url changed to "http://www.spareka.fr/piece_detachees_accessoires_electromenager"
[debug] [phantom] Navigation requested: url=http://googleads.g.doubleclick.net/pagead/viewthroughconversion/1009678515/?random=1413232851719&cv=7&fst=1413232851719&num=1&fmt=1&guid=ON&u_h=768&u_w=1024&u_ah=768&u_aw=1024&u_cd=32&u_his=1&u_tz=120&u_java=false&u_nplug=0&u_nmime=0&frm=0&url=http://www.spareka.fr/piece_detachees_accessoires_electromenager, type=Other, willNavigate=true, isMainFrame=false
[debug] [phantom] Navigation requested: url=http://www.google.com/ads/user-lists/1009678515/?fmt=1&num=1&cv=7&frm=0&url=http://www.spareka.fr/piece_detachees_accessoires_electromenager&random=4196938409, type=Other, willNavigate=true, isMainFrame=false
[debug] [phantom] Navigation requested: url=http://www.google.fr/ads/user-lists/1009678515/?fmt=1&num=1&cv=7&frm=0&url=http://www.spareka.fr/piece_detachees_accessoires_electromenager&random=4196938409&ipr=y, type=Other, willNavigate=true, isMainFrame=false
[debug] [phantom] Successfully injected Casper client-side utilities
[info] [phantom] Step anonymous 2/2 http://www.spareka.fr/piece_detachees_accessoires_electromenager (HTTP 200)
[debug] [phantom] Capturing page to /home/asus4/Bureau/tests casper/test/screen01.png
[info] [phantom] Capture saved to /home/asus4/Bureau/tests casper/test/screen01.png
[info] [phantom] Step anonymous 2/2: done in 3227ms.
[info] [phantom] Step _step 3/3 http://www.spareka.fr/piece_detachees_accessoires_electromenager (HTTP 200)
[info] [phantom] Step _step 3/3: done in 3228ms.
[info] [phantom] wait() finished waiting for 10000ms.
[debug] [phantom] Capturing page to /home/asus4/Bureau/tests casper/test/screen02.png
[info] [phantom] Capture saved to /home/asus4/Bureau/tests casper/test/screen02.png
CasperError: Errors encountered while filling form: form not found
/home/asus4/Bureau/dev/casperjs/modules/casper.js:805 in fillForm
/home/asus4/Bureau/dev/casperjs/modules/casper.js:880 in fillSelectors
/home/asus4/Bureau/tests casper/test/script_test.js:28
/home/asus4/Bureau/dev/casperjs/modules/casper.js:2035 in _check

My code :

var casper = require("casper").create({
  verbose: true,
  logLevel: "debug"
});

casper.start("http://www.spareka.fr/piece_detachees_accessoires_electromenager", function(){


//this.echo(this.getHTML('body'));

  this.on('remote.message', function(msg){
    this.echo("remote.message : " + msg);
  });
  this.on('page.error', function(msg, trace){
    this.echo("Error:   " + msg, "ERROR");
    this.echo("file:    " + trace[0].file, "WARNING");
    this.echo("line:    " + trace[0].line, "WARNING");
    this.echo("function:    " + trace[0]["function"], "WARNING");
    errors.push(msg);
  });

  this.capture("screen01.png");
  this.wait(10000, function(){
    this.capture("screen02.png");
    this.fillSelectors("form#search_form_4", {
  //'input[id="#finalProductType"]':    'Appareil à Fondue',
  //'input[id="#manufacturer"]':        'TEFAL',
    });
  });

You should be using "form#search-form-4" instead.

Replace the underscores with dashes. I checked the page you mentioned and it has a form with id="search-form-4".

链接地址: http://www.djcxy.com/p/73482.html

上一篇: CasperJS / PhantomJS Cookie处理

下一篇: CasperJS,测试页面无法完全加载