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

anu
  • 1,076
  • 10
  • 20

3 Answers3

9

There is also another way:

fill_in :placeholder => "Fill in some text", :with => "Text"
x3qt
  • 310
  • 2
  • 7
  • 1
    From at least version Capybara 2.3 (maybe earlier) fill_in finds placeholder text. – IAmNaN Jun 26 '14 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 '15 at 17:58
7

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

find("input[placeholder='First Name']").set "value"
Tanzeeb Khalili
  • 7,324
  • 2
  • 23
  • 27
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

juliangonzalez
  • 4,231
  • 2
  • 37
  • 47