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

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

问题描述

我想执行以下操作,但由于 fill_in 期望定位器作为第一个参数的性质,我无法执行.

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"

我也试过了

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.

关于通过正则表达式查找字段以与 fill_in 一起使用的最佳方法的任何想法?

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

推荐答案

如果你有对元素本身的引用,你会使用 set 而不是 fill_in:

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")

但是对于您的具体示例,fill_in 应该能够找到您知道的元素 ID:

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"

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

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