2
votes

I'm running into some trouble attempting to fill_in a Text form on a form group.

HTML:

<div class="form-group">
    <label class="control-label">First Name</label>
    <input class="form-control" type="text" data-filter="0">
</div>

I've tried using fill_in via using the label text IE "First Name" with no luck; I've also tried using the "data-filter="0"" with no luck (I'm not even sure what this is; it doesn't seem to be an id of any sort).

I figured maybe I could use the xpath? but can you even do a finder on the xpath of something and then fill it in? I couldn't find anything that seemed to reference being able to in the capybara module docs.

1
The reason the label text doesn't work is because the label isn't tied to the input in any way - it would need to either have a for attribute whose value would be the id of the input (if there was one), or it would need to wrap the input to tie it to the inputThomas Walpole

1 Answers

2
votes

An alternative would be to use find and set:

find(:xpath, "//label[text()='First Name']/following-sibling::input").set("text")

Or:

find(:xpath, "//div[label='First Name']/input").set("text")