Forum: RSpec Webrat - Fill in text field by id

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
08fbedeb4ba773a4861c2537ee5c95d6?d=identicon&s=25 Steve Molitor (Guest)
on 2009-03-06 17:53
(Received via mailing list)
Is there a way to locate and 'fill in' a text field (or check a check
box,
select an option, etc.) by id?  It seems that the fill_in method takes
either the text of the label pointing to the field or the field name.
The
are cases when writing cucumber steps when using the HTML id of the
input
element would be easier, especially when a page has multiple forms with
the
same labels and input names.
Thanks,

Steve
171ea139761951336b844e708d1547ab?d=identicon&s=25 James Byrne (byrnejb)
on 2009-03-06 18:03
Steve Molitor wrote:
> Is there a way to locate and 'fill in' a text field (or check a check
> box,
> select an option, etc.) by id?  It seems that the fill_in method takes
> either the text of the label pointing to the field or the field name.
> The
> are cases when writing cucumber steps when using the HTML id of the
> input
> element would be easier, especially when a page has multiple forms with
> the
> same labels and input names.
> Thanks,
>
> Steve


Yes, just provide the text of the id selector, do not add anything else.

So, for an id="test_this_id" on a button you can write in your
test/definition:

click_button("test-this_id")
171ea139761951336b844e708d1547ab?d=identicon&s=25 James Byrne (byrnejb)
on 2009-03-06 18:04
James Byrne wrote:
S/B
>
> click_button("test_this_id")
874be46e8593deadb2cec84b70b26725?d=identicon&s=25 Yi Wen (hayafirst)
on 2009-03-06 18:17
(Received via mailing list)
It does take id. At least in the trunk webrat
08fbedeb4ba773a4861c2537ee5c95d6?d=identicon&s=25 Steve Molitor (Guest)
on 2009-03-06 21:31
(Received via mailing list)
Well I'm reading the 0.4.2 webrat rdoc for fill_in, at it says:
"field can be either the value of a name attribute (i.e. user[email]) or
the
text inside a <label>element that points at the <input> field."

Does it also try the id?

Steve
994e42bda994be2cd1d791f18ee6d561?d=identicon&s=25 Stephen Eley (Guest)
on 2009-03-06 21:50
(Received via mailing list)
On Fri, Mar 6, 2009 at 2:22 PM, Steve Molitor <stevemolitor@gmail.com>
wrote:
> Well I'm reading the 0.4.2 webrat rdoc for fill_in, at it says:
> "field can be either the value of a name attribute (i.e. user[email]) or the
> text inside a <label>element that points at the <input> field."
> Does it also try the id?

Try it!  (Or read the code.  Or both.)



--
Have Fun,
   Steve Eley (sfeley@gmail.com)
   ESCAPE POD - The Science Fiction Podcast Magazine
   http://www.escapepod.org
874be46e8593deadb2cec84b70b26725?d=identicon&s=25 Yi Wen (hayafirst)
on 2009-03-06 22:21
(Received via mailing list)
Could you just try it?
This topic is locked and can not be replied to.