D
D
Daniil Laptev2014-02-18 13:08:27
Ruby on Rails
Daniil Laptev, 2014-02-18 13:08:27

Why does Capybara not see the checkbox?

Here is a snippet from the form:

<div class='cr-cat'>
                  <ul>
                    <li>
                      <input disabled='disabled' id='cat-17' name='cat' type='checkbox' value='cat17'>
                      <label for='cat-17' onclick="$('.podcat#17').slideToggle('fast');">Программирование</label>
                      <ul class='podcat' id='17' style='display: none;'>
                        <li>
                          <input id="task_subcategories_12" name="task[subcategories][]" type="checkbox" value="12" />
                          <label for='task_subcategories_12'>Python</label>
                        </li>
                      </ul>
                    </li>
                  </ul>
                </div>

When you click on <label for='cat-17'>..., subcategories are expanded, which, in fact, you need to select.
Tried like this: like this
check 'Python'
:
check '#task_subcategories_12'
like this:
find(:xpath, "//input[@value='task_subcategories_#{@subcategory.id}']").set(true)

And even like this (just in case, expanding the category):
find(:xpath, "//input[@value='cat#{@category.id}']").set(true)
find(:xpath, "//input[@value='#{@subcategory.id}']").set(true)

Expands the category without error, but does not see the subcategory.
In all cases, errors like:
Unable to find xpath "//input[@value=''12"]" ...
What else would you advise?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dimitriy, 2014-05-27
@TakteS

Well, if you really test, then test until the end :)

find("label[for^='cat-17']").click
expect(page).to have_selector("#task_subcategories_12")

on the subject, for invisible: visible: false
expect(page).to have_selector("#task_subcategories_12", visible: false)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question