CasperJS: swallows special keys like Enter?

前端 未结 1 534
旧时难觅i
旧时难觅i 2020-12-15 01:52

I\'m trying to write a test using CasperJS for a scenario where pressing Enter in an input is the trigger for the page to do something with the text otherwise typed into the

相关标签:
1条回答
  • 2020-12-15 02:10

    You might want to add {keepFocus: true} to the first sendKeys call. If you see the source code, without adding a keepFocus, it is blurring the text area and that means your second sendKeys call will not accept the keypress.

    This seems to work.

    casper.start('http://localhost:3000/input-demo', function() {
      this.sendKeys('#demo-input', 'demo text', {keepFocus: true});
      this.sendKeys('#demo-input', casper.page.event.key.Enter , {keepFocus: true});
      this.test.assertEquals(this.getHTML('#stage'), 'input demo');
    });
    
    casper.run();
    
    0 讨论(0)
提交回复
热议问题