Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Capybara: won't select bootstrap button group

I have the following button group that I cannot get Capybara w/ Selenium to select for:

<div class="btn-group hidden-sm" data-toggle-name="user[attributes][0][customization_id]" data-toggle="buttons">
  <label class="btn btn-default active">
    <input type="radio" value="17">
      Stocky body
  </label>
  <label class="btn btn-default">
    <input type="radio" value="16">
      Round body
  </label>
</div>

I have tried to following:

click_button 'Stocky body'

find(:xpath, "//input[@value='16']").click

and

find(:xpath, "//input[@type='radio'][@value='16']").click

At this point I've ready over an hour of :xpath and Capybara answers and they all see to be saying that the :xpath code should at least work.

Can anyone shed light on what I'm doing wrong here?

like image 328
mztwo Avatar asked Jul 10 '26 02:07

mztwo


1 Answers

I found the solution, because input tags aren't closed I need to use Capybara and find the tags.

The following code was able to work:

page.find('label', text: 'Stocky body').click

Hope this helps anyone else trying to use Capybara with Bootstrap-styled selectors!

like image 155
mztwo Avatar answered Jul 17 '26 11:07

mztwo



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!