有没有一种方法可以使用Capybara将按键发送到Webkit?

编程入门 行业动态 更新时间:2024-10-08 04:26:44
本文介绍了有没有一种方法可以使用Capybara将按键发送到Webkit?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

在使用Capybara和WebKit的集成测试中,我需要向Web应用程序发送一些按键.使用Selenium(WebDriver和Firefox),我可以这样实现:

I need to send some key-presses to a web app in an integration test that uses Capybara and WebKit. Using Selenium (WebDriver and Firefox) I can achieve it like this:

find("#element_id").native.send_keys :tab

,但是WebKit的本机元素节点没有send_keys方法.实际上,WebKit中的native返回了一个包含数字的字符串.还有另一种将击键发送到WebKit的方法吗?甚至可能没有使用JavaScript/jQuery的解决方法?

but WebKit's native element node doesn't have a send_keys method. Actually native in WebKit returned a string containing a number. Is there another way to send keystrokes to WebKit? Maybe even some workaround using JavaScript/jQuery?

推荐答案

我一直在尝试实现Marc的答案,但没有成功,但是我从类似的问题中找到了一些帮助: capybara:在表单字段中输入值并用Enter键终止..显然有一个来自水豚的拉动请求,似乎可以解决此问题.

I've been trying to implement Marc's answer without any success, but I found some help from a similar question: capybara: fill in form field value with terminating enter key. And apparently there was a pull request from capybara that seems to address this issue.

对我有用的是:

before { fill_in "some_field_id", with: "\t" }

我的示例删除了该字段中的文本,然后按 Tab .要用'foobar'填写字段,请将"\t"替换为"foobar\t".您还可以使用"\n"作为 Enter 键.

My example erases the text in the field and then presses Tab. To fill in a field with 'foobar', replace "\t" with "foobar\t". You can also use "\n" for the Enter key.

例如,您可以使用:

find("#element_id").set("\t")

更多推荐

有没有一种方法可以使用Capybara将按键发送到Webkit?

本文发布于:2023-11-25 21:04:06,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1631339.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:可以使用   发送到   按键   方法   Capybara

发布评论

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

>www.elefans.com

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