Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use fill_in with find in Capybara (if possible)

Tags:

find

capybara

I'd like to do the following but can't due to the nature of fill_in expecting a locator as the first argument.

find(:css, "input[id$='donation_pledge_hundreds']").fill_in :with => "10"

I've also tried doing

element = find(:css, "input[id$='donation_pledge_hundreds']")   
fill_in element.<method> , :with => "10"

but there are no methods that return any data to identify the element to fill_in.

Any ideas of the best way of finding a field via a regex for use with fill_in?

like image 481
ants Avatar asked Dec 16 '11 12:12

ants


3 Answers

If you have a reference to the element itself you'd use set instead of fill_in:

find(:css, "input[id$='donation_pledge_hundreds']").set("10")

However for your specific example, fill_in should be able to find the element as you know it's ID:

fill_in 'donation_pledge_hundreds', with: "10"
like image 188
Jon M Avatar answered Oct 17 '22 05:10

Jon M


element = find(:css, "input[id$='donation_pledge_hundreds']")   
element.fill_in with: "10"
like image 8
aki Avatar answered Oct 17 '22 04:10

aki


Instead of a method, you can use brackets to return :name or :id, e.g. element = find(:css, "input[id$='donation_pledge_hundreds']") fill_in element[:name], :with => "10" The same approach can be used with select - select my_type, from: find('select[name$="[type]"]')[:name]

like image 5
bhfailor Avatar answered Oct 17 '22 03:10

bhfailor