Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Finding the last element with the same class in Capybara and filling it with some text

I've following markup:

<div class='foo'>
  <form>
    <input class='bar' type='text'>
  </form>
<div/>

<div class='foo'>
  <form>
    <input class='bar' type='text'>
  </form>
</div>

I'd like to fill input in the second .foo container. How I can achieve this in Capybara ?

like image 271
Leszek Andrukanis Avatar asked Dec 07 '13 16:12

Leszek Andrukanis


1 Answers

What about:

within all('.foo').last do
  find('.bar').set 'a value'
end

Check within and set.

like image 64
sites Avatar answered Nov 20 '22 08:11

sites