#240 ✓resolved
Michael Kintzer

fill_in 'could not find field' when label in table cell

Reported by Michael Kintzer | May 8th, 2009 @ 12:08 AM

I'm using Webrat (0.4.4) as part of Cucumber (0.3.2) and I'm unable to use the content of the label tag as the parameter for the fill_in method.

When I fill in "user[login]" with "any_login" - works.

When I fill in "Username" with "any_login" - fails with Could not find field: "Username" (Webrat::NotFoundError):



Comments and changes to this ticket

  • Michael Kintzer

    Michael Kintzer May 8th, 2009 @ 12:11 AM

    Sorry, html example did not come through. See attached file.

  • gaffo

    gaffo May 15th, 2009 @ 08:40 PM

    • State changed from “new” to “resolved”

    You don't seem to have a field named "username". The way that the label for= works is that it refers to the name of the field that you want to click on. I'm going to mark this as resolved for now, but if you could view source on your page and send that in or try changing the for to be for="login" and it doesn't work, we will re-open this.

    Thanks for the input!

  • Michael Kintzer

    Michael Kintzer May 16th, 2009 @ 11:58 AM

    Sorry for the confusion. I meant to include the html source and not the embedded Ruby. I have attached that snippet.

    I've tried "username" (the value of the 'for' attribute of the label tag), "Username" (the innerHTML text inside the label tag), and "login" (the model attribute). None of those work.

    Only "user[login]" (the 'name' attribute of the label's associated input element) works.

    Please review again. Thanks.

  • Michael Kintzer

    Michael Kintzer May 16th, 2009 @ 12:17 PM

    So I reread your post again and it seems like you are saying the value of the 'for' attribute on the label tag should be the same as the value of the 'name' attribute on the input tag. Is that correct? FWIW, I tried that as well and it still does not work for me. See attached.

    Perhaps you could include an example for me where the model attribute name is not the same as the innerHTML of the label.

    Feeling very newbie-ish here.

  • gaffo

    gaffo May 16th, 2009 @ 03:54 PM

    Try changing your html to be like what is attached. I was wrong and label for is to connect with the ID of the field.

  • Michael Kintzer

    Michael Kintzer May 16th, 2009 @ 08:22 PM

    That works. Thanks for your help gaffo. I'd kindly suggest that the Rdoc for fill_in is changed to be more explicit about this.

    Currently it says "field can be either the value of a name attribute (i.e. user[email]) or the text inside a element that points at the field. "

    "points at" wasn't explicit enough for me, obviously.

Please Sign in or create a free account to add a new ticket.

With your very own profile, you can contribute to projects, track your activity, watch tickets, receive and update tickets through your email and much more.

New-ticket Create new ticket

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile ยป

Ruby Acceptance Testing for Web applications.

Shared Ticket Bins

People watching this ticket