水豚-提交不带按钮的表格 [英] Capybara - Submit a form without button

查看:82
本文介绍了水豚-提交不带按钮的表格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试仅使用Capybara和Rspec提交不带按钮的表单(没有黄瓜或Selenium,我知道已经有关于此的问题了.)

I am trying to submit a form without button using just Capybara and Rspec (no Cucumber or Selenium, I know there is already a question about that).

我已经看到有一个要点,可以添加一种无需按钮即可提交表单的方法:

I've seen there is a gist to add a method to submit a form without button:

module SubmitRackTestFormWithoutButton
  def submit_form!
    Capybara::RackTest::Form.new(driver, form).submit({})
  end
end
Capybara::RackTest::Node.send :include, SubmitRackTestFormWithoutButton

https://gist.github.com/989533 ,但我没有使它起作用,我留下了一个对此发表评论:

https://gist.github.com/989533, but I've not gotten it to work and I left a comment on it:

我得到未定义的方法'submit_form!'对于#Capybara :: Node :: Element:... 实际上是通过"Capybara :: RackTest :: Node.send:include, SubmitRackTestFormWithoutButton"方法上将Submit_form!添加到 节点(不是元素),而是找到返回元素

I get undefined method `submit_form!' for #Capybara::Node::Element:... actually by "Capybara::RackTest::Node.send :include, SubmitRackTestFormWithoutButton" the method submit_form! is added to the Node (not to the Element), but find return an Element

您是否有解决这个问题的主意,或者有其他解决方案来提交不带按钮的表单?

Do you have some idea to work out that gist, or some other solution to submit a form without button ?

谢谢

推荐答案

尽管使用水豚可以实现您想要的功能,但更简单实用的解决方案是在表单上放置一个提交按钮.

Although it's possible to achieve what you want using capybara, the easier and more practical solution is to put a submit button on the form.

没有理由在表单上没有按钮,没有表单是很糟糕的可访问性,并且没有GUI或正在使用屏幕阅读器的用户将很难提交表单.

There is no reason to not have a button on the form, it's bad accessibility to not have a form and users that do not have a GUI or are using screen readers will have trouble submitting the form otherwise.

如果您不希望显示表单按钮,我可以建议使用一些CSS使其隐藏:

If you don't want the form button to be visible, can I suggest using some CSS to make it hidden:

<input type="submit" style="position: absolute; left: -9999px; width: 1px; height: 1px;">

这篇关于水豚-提交不带按钮的表格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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