1

i'm wondering why cannot get casperjs to recognize the modal popup:

var casper = require('casper').create();
casper.start('http://www.zulutrade.com/trader/140682?Lang=en');
casper.waitForSelector("form[name=aspnetForm] button#main_BtnFollow",
function success() {
    this.test.assertExists("form[name=aspnetForm] button#main_BtnFollow");
    this.click("form[name=aspnetForm] button#main_BtnFollow");
},
function fail() {
    this.test.assertExists("form[name=aspnetForm] button#main_BtnFollow");
});

casper.waitForPopup(/popup\.html$/, function() {
    this.test.assertEquals(this.popups.length, 1);
});
casper.run(function() {this.test.renderResults(true);});

running the above gives me timeout in the waitForPopup part..

How to make this work and how to use casper.withPopup properly with the popup?

4

2 に答える 2

3

あ、レザレクト使ってる?私の経験では、生成されるスクリプトを微調整する必要があります。私は主に要素名にのみ使用します。

あなたのスクリプトにはアサートしか表示されません。モーダルが表示される前に、キャスパーに何かをクリックするように指示する必要があると思います。このようなものでしょうか?

casper.then(function() {
    this.clickLabel('.Follow', 'a');
});

casper.waitForSelector("#modal_popup", function() {
    this.echo('see the modal!');
    this.capture('screenshotofmodal.png', { top: 0, left:0, width:1000, height:  4000}); 
 }); 

PS
capture() を使用すると、スクリプトのトラブルシューティングに非常に役立ちます。私はそれらを一種のブレークポイントとして持っており、合格するはずのテストが失敗した場合に何が起こっているのかを簡単に確認できます。

于 2013-09-24T19:56:49.650 に答える
1

私は、キャスパーがモーダルインタラクションでうまく動作するようにするために、大雑把なタイムアウトを実装していることに気付きました。

casper.start(uri).then(function() {
  var slideshow = 'a.photo_gallery_icon_modal_launch';
  casper.wait(2000, function(){
    casper.thenEvaluate(function(sel) {
      $elem = jQuery(sel).first();
      $elem.click();
    }, slideshow)
  }).wait(1000, function(){
    // wait a sec for modal to show up before taking pic
    casper.capture('foo.png', {
      top: 0,
      left: 0,
      width: 1280,
      height: 1024
    })
  })
});

もありますがwaitForSelector、モーダルの内容も非同期であり、waitまたはwaitForUrlより適切に使用できるため、それほど成功していません。

http://docs.casperjs.org/en/latest/modules/casper.html#waitforselector

于 2016-03-10T22:29:47.833 に答える