Search code examples
twitter-bootstrapxpathseleniumcapybaracapybara-webkit

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?


Solution

  • 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!