开发者

capybara's fill_in method not working as expected

I have 2 forms in my page. The first form has a field "Username" and the second form has a field "Username:".

When fill_in label, :with => value is run (where label = "Username:"), the input box labeled "Username" is getting filled instead.

I changed "Username:" to "User name:" but even then "Username" get开发者_如何学运维s filled.

What am I doing wrong?


If I understand correctly, you have 2 identically named text inputs on 2 different forms on your page.

I believe fill_in some_field will look for an input with a name or ID matching some_field, rather than reading an attached label. Edit: It does actually look for an attached label - thanks to AlistairH for the correction

I would suggest the best way to get the behaviour you want is using a within block:

within 'form1' do
    fill_in 'Username', :with => value
end

Replace 'form1' with the name of whichever form contains the textbox you'd like to target.

I would consider this to be far more reliable, and readable, than relying on the presence of spaces or colons to differentiate between almost identically named elements on the page

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜