如何在水豚中使用fill_in(如果可能的话) [英] How to use fill_in with find in Capybara (if possible)

查看:152
本文介绍了如何在水豚中使用fill_in(如果可能的话)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想做下面的事情,但不能因为fill_in的性质而期望locator作为第一个参数。

  find(:css,input [id $ ='donation_pledge_hundreds'])。fill_in:with => 10

我也试过了

  element = find(:css,input [id $ ='donation_pledge_hundreds'])
fill_in元素< method> ,:with => 10

但是没有方法返回任何数据来标识fill_in元素。 p>

任何通过正则表达式找到字段的最佳方式的任何想法用于fill_in?

解决方案

从内存开始,所以可能不是100%正确,但是我认为如果你有一个引用元素本身,你可以使用 set 来代替 fill_in

  find(:css,input [id $ ='然而,对于你的具体例子,<$ c($ don').set。(10)

$ c $> fill_in 应该能够找到元素,就像你知道它的ID一样:

  fill_in' donation_pledge_hundreds',其中:10


I'd like to do the following but can't due to the nature of fill_in expecting a locator as the first argument.

find(:css, "input[id$='donation_pledge_hundreds']").fill_in :with => "10"

I've also tried doing

element = find(:css, "input[id$='donation_pledge_hundreds']")   
fill_in element.<method> , :with => "10"

but there are no methods that return any data to identify the element to fill_in.

Any ideas of the best way of finding a field via a regex for use with fill_in?

解决方案

Going from memory so may not be 100% correct, but I think if you have a reference to the element itself you'd use set instead of fill_in:

find(:css, "input[id$='donation_pledge_hundreds']").set("10")

However for your specific example, fill_in should be able to find the element as you know it's ID:

fill_in 'donation_pledge_hundreds', with: "10"

这篇关于如何在水豚中使用fill_in(如果可能的话)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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