9

In my rspec test, how do I fill_in a text field using Placeholder. I cannot use id and name as they are auto generated for the nested form.

<input class="input-medium inline" id="user_kids_attributes_new_1342116887461_first_name" name="user[kids_attributes][new_1342116887461][first_name]" placeholder="First Name" size="30" type="text">

Thanks

3 Answers 3

9

There is also another way:

fill_in :placeholder => "Fill in some text", :with => "Text"
2
  • 1
    From at least version Capybara 2.3 (maybe earlier) fill_in finds placeholder text.
    – IAmNaN
    Jun 26, 2014 at 17:40
  • 4
    Capybara 2.5, you should not specify placeholder key but use it like fill_in "placeholder name", with: "text"
    – freemanoid
    Oct 14, 2015 at 17:58
7

Placeholder support will be in the next version of Capybara. For now, try:

find("input[placeholder='First Name']").set "value"
0
0

'Card number' being the placeholder

This should work, EXCEPT you're trying to fill an input inside an iframe

In that case: https://stackoverflow.com/a/53227758/1248725

fill_in('Card number', with: "#{arg1} #{arg2} #{arg3} #{arg4}")

This

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.