CasperJS click()无法调度mousedown事件错误(CasperJS click() cannot dispatch mousedown event error)

系统教程 行业动态 更新时间:2024-06-14 17:01:31
CasperJS click()无法调度mousedown事件错误(CasperJS click() cannot dispatch mousedown event error)

我正在使用CasperJS 1.1并且我想模拟单击文件字段,但是当我运行测试时(项目使用AngularJS fwiw)我收到错误:

# Create gallery page PASS File field exists FAIL Cannot dispatch mousedown event on nonexistent selector: input#gallery_file_0 # type: uncaughtError # file: spec/javascripts/casperjs/create_gallery.coffee:1323 # error: Cannot dispatch mousedown event on nonexistent selector: input#gallery_file_0 # CasperError: Cannot dispatch mousedown event on nonexistent selector: input#gallery_file_0 # at mouseEvent (/usr/local/Cellar/casperjs/1/libexec/modules/casper.js:1323) # at click (/usr/local/Cellar/casperjs/1/libexec/modules/casper.js:428) # at spec/javascripts/casperjs/create_gallery.coffee:7 # at runStep (/usr/local/Cellar/casperjs/1/libexec/modules/casper.js:1523) # at checkStep (/usr/local/Cellar/casperjs/1/libexec/modules/casper.js:368) # stack: not provided

这个错误对我来说没有意义,因为我之前关于输入字段存在的断言实际上是正确的。 这是测试文件:

casper.test.begin "Create gallery page", 1, (test) -> casper.start "http://localhost:3000/galleries/new", -> @then -> test.assertField("input#gallery_file_0", null, "File field exists") @click("input#gallery_file_0") casper.run()

可能是什么问题?

版本:

casperjs --version 1.1.0-DEV phantomjs -v 1.9.1 MacOSX 10.8.4

I'm using CasperJS 1.1 and I want to simulate clicking on a file field, but I'm getting an error when I run the test (the project is using AngularJS fwiw):

# Create gallery page PASS File field exists FAIL Cannot dispatch mousedown event on nonexistent selector: input#gallery_file_0 # type: uncaughtError # file: spec/javascripts/casperjs/create_gallery.coffee:1323 # error: Cannot dispatch mousedown event on nonexistent selector: input#gallery_file_0 # CasperError: Cannot dispatch mousedown event on nonexistent selector: input#gallery_file_0 # at mouseEvent (/usr/local/Cellar/casperjs/1/libexec/modules/casper.js:1323) # at click (/usr/local/Cellar/casperjs/1/libexec/modules/casper.js:428) # at spec/javascripts/casperjs/create_gallery.coffee:7 # at runStep (/usr/local/Cellar/casperjs/1/libexec/modules/casper.js:1523) # at checkStep (/usr/local/Cellar/casperjs/1/libexec/modules/casper.js:368) # stack: not provided

The error doesn't make sense to me, because my previous assertion that the input field exists is actually true. Here is the test file:

casper.test.begin "Create gallery page", 1, (test) -> casper.start "http://localhost:3000/galleries/new", -> @then -> test.assertField("input#gallery_file_0", null, "File field exists") @click("input#gallery_file_0") casper.run()

What might be the problem?

Versions:

casperjs --version 1.1.0-DEV phantomjs -v 1.9.1 MacOSX 10.8.4

最满意答案

使用以下行,看起来好像您实际上正在检查字段的值是否为null ,当字段不存在时,该值似乎为true。

test.assertField("input#gallery_file_0", null, "File field exists")

相反,你应该使用:

test.assertExists("input#gallery_file_0", "File field exists");

With the following line, it looks as though you are actually checking if the value of the field is null, which appears to be true when the field doesn't exist.

test.assertField("input#gallery_file_0", null, "File field exists")

Instead, you should probably use:

test.assertExists("input#gallery_file_0", "File field exists");

更多推荐

本文发布于:2023-04-20 16:16:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/dzcp/9d9c8fef947d493a95d8b012a43b860f.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:错误   事件   mousedown   CasperJS   click

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!