capybara:使用回车键填写表单字段值 [英] capybara: fill in form field value with terminating enter key

查看:69
本文介绍了capybara:使用回车键填写表单字段值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在测试条形码阅读器的输入...它的行为类似于键盘,但是使用回车键字符终止每个条形码。我的javascript检测到Enter键并做出响应(backbone.js应用程序)。

I'm testing a barcode reader input... it behaves like the keyboard but terminates each barcode with the enter key character. My javascript detects the enter key and responds (backbone.js application).

我如何用带有终止Enter键值的字符串填充表单字段?

How can I "fill in" a form field with a string that has a terminating enter key value?

我的测试堆栈是黄瓜/水豚/水豚-webkit。

My test stack is cucumber/capybara/capybara-webkit.

推荐答案

实际上,您似乎可以向水豚的本机设置方法发送 capn 并获得相同的效果(以一种更加灵活,与驱动程序无关的方式)。

Actually, it seems that you can just send a \n to capybara's native set method and achieve the same effect (in a more flexible, driver agnostic way).

所以在我的代码中,这当前正在触发表单提交事件(由JS处理):

So in my code, this is currently working to trigger a form submit event (handled by JS):

  field = find("form input[type=text]")
  field.set "my comment\n"

(请注意,正如pull请求的作者所解释的那样此处,这仅在您绑定到特定的keydown事件时才有效,而在绑定到表单提交时则无效应该是由此产生的。)

(Note that, as the author of the pull request explains here, this only works if you're binding to the specific keydown event, not if you're binding to the form submit that should result from it.)

这篇关于capybara:使用回车键填写表单字段值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆