我想做以下但不能由于fill_in的性质期望定位器作为第一个参数.
find(:css, "input[id$='donation_pledge_hundreds']").fill_in :with => "10"
Run Code Online (Sandbox Code Playgroud)
我也尝试过
element = find(:css, "input[id$='donation_pledge_hundreds']")
fill_in element.<method> , :with => "10"
Run Code Online (Sandbox Code Playgroud)
但是没有方法可以返回任何数据来识别fill_in元素.
有关通过正则表达式查找字段以与fill_in一起使用的最佳方法的任何想法吗?
Jon*_*n M 155
从内存开始可能不是100%正确,但我认为如果你有一个元素本身的引用,你将使用set而不是fill_in:
find(:css, "input[id$='donation_pledge_hundreds']").set("10")
Run Code Online (Sandbox Code Playgroud)
但是对于您的具体示例,fill_in应该能够找到您知道它的ID的元素:
fill_in 'donation_pledge_hundreds', with: "10"
Run Code Online (Sandbox Code Playgroud)
小智 8
element = find(:css, "input[id$='donation_pledge_hundreds']")
element.fill_in with: "10"
Run Code Online (Sandbox Code Playgroud)
您可以使用括号返回:name或代替方法,:id例如
,可以使用
element = find(:css, "input[id$='donation_pledge_hundreds']")
fill_in element[:name], :with => "10"
相同的方法select-
select my_type, from: find('select[name$="[type]"]')[:name]