CasperJS,测试页面无法完全加载

我是casperjs的新手,我想测试此页面的下拉列表:http://www.spareka.fr/pieces_detachees_accessoires_electromenager

该元素位于页面的右上方(“Quel type d'appareil?”)。 所以,我运行这个脚本:

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

但我的外壳显示这个错误:“表单未找到”我检查了,选择器是好的。 因此,我在脚本的开头捕捉页面,并注意到我的页面没有加载每个元素(id为“search_form_4”的表单不可见)。

我想我的网页需要时间加载,所以我使用this.wait是这样的:

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

但最后,screen01显示的内容与screen02相同。 我不明白为什么当我使用CasperJS时页面不能完全加载:/你能帮我吗?

编辑:我的日志:

asus4 @ asus4-VirtualBox〜/ Bureau / tests casper / test $ sudo casperjs script_test.js
[信息] [幻影]开始...
[info] [phantom]跑步套件:2个步骤
[debug] [phantom]打开url:http://www.spareka.fr/piece_detachees_accessoires_electromenager,HTTP GET
[debug] [phantom]导航请求:url = http://www.spareka.fr/piece_detachees_accessoires_electromenager,type =其他,willNavigate = true,isMainFrame = true
[debug] [phantom] url更改为“http://www.spareka.fr/piece_detachees_accessoires_electromenager”
[debug] [phantom]导航请求: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 =其他,willNavigate = true,isMainFrame = false
[debug] [phantom]导航请求: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]导航请求: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]成功注入Casper客户端实用程序
[info] [phantom] Step anonymous 2/2 http://www.spareka.fr/piece_detachees_accessoires_electromenager(HTTP 200)
[debug] [phantom]将页面捕获到/ home / asus4 / Bureau / tests casper / test / screen01.png
[info] [phantom] Capture保存到/ home / asus4 / Bureau / tests casper / test / screen01.png
[info] [phantom]匿名步骤2/2:在3227ms完成。
[info] [phantom] Step _step 3/3 http://www.spareka.fr/piece_detachees_accessoires_electromenager(HTTP 200)
[info] [phantom] Step_step 3/3:在3228ms完成。
[等待] [幻影] wait()等待10000ms。
[debug] [phantom]将页面捕获到/ home / asus4 / Bureau / tests casper / test / screen02.png
[info] [phantom] Capture保存到/ home / asus4 / Bureau /测试casper / test / screen02.png
CasperError:填写表单时遇到的错误:未找到表单
/home/asus4/Bureau/dev/casperjs/modules/casper.js:805 in fillForm
/ fill / select /
/ home / asus4 / Bureau / tests casper / test / script_test.js:28
在_check中/home/asus4/Bureau/dev/casperjs/modules/casper.js:2035

我的代码:

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',
    });
  });

你应该使用"form#search-form-4"代替。

用破折号替换下划线。 我检查了你提到的页面,它有一个id =“search-form-4”的表单。

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

上一篇: CasperJS, the test page doesn't load totally

下一篇: casperjs tests freezing causing jenkins build to time out