在使用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?
发布评论