无法找到水豚的复选框
Unable to find checkbox with Capybara
无法找到 Capybara 的复选框。
这是HTML:
<div class='check-group'>
<div class='checkbox'>
<input type="checkbox" name="accepts_fcra" id="accepts_fcra" value="1" />
<label for="accepts_fcra"><span>Some text <a title="FCRA" target="_blank" href="https://www.google.com/fcra">FCRA</a> some text.</span></label>
</div>
</div>
现在我想选中 ID 为 "accepts_fcra" 的复选框。
我已经尝试了很多东西,而且几乎都是 return 相同的东西:"Unable to find (method used to find checkbox)"
一些尝试:
check("#accepts_fcra")
Capybara::ElementNotFound: Unable to find checkbox "#accepts_fcra"
find("#accepts_fcra").set true
Capybara::ElementNotFound: Unable to find css "#accepts_fcra"
within("div.checkbox") do
find(:xpath, "//input[@id='accepts_fcra']")
end
Capybara::ElementNotFound: Unable to find xpath "//input[@id='accepts_fcra']"
但是checkbox上面的2个类,“.check-group”和“.checkbox”都找到了,只是没有找到checkbox。想法?
想通了,试过这个:
find("accepts_fcra", :visible => false).click
它起作用了,元素是 'invisible',所以只需将它与查找一起传递并单击它就可以起作用。
visible: false
解决方案对我不起作用。
这是因为复选框被隐藏了,像这样
input[type="checkbox"]{
position: absolute;
opacity: 0;
cursor: pointer;
height: 0;
width: 0;
opacity:0;
}
并且使用了时髦的复选标记样式。
但是,点击标签对我有用
例如/
page.find(:xpath, "//label[@for='accepts_fcra']").click
无法找到 Capybara 的复选框。
这是HTML:
<div class='check-group'>
<div class='checkbox'>
<input type="checkbox" name="accepts_fcra" id="accepts_fcra" value="1" />
<label for="accepts_fcra"><span>Some text <a title="FCRA" target="_blank" href="https://www.google.com/fcra">FCRA</a> some text.</span></label>
</div>
</div>
现在我想选中 ID 为 "accepts_fcra" 的复选框。
我已经尝试了很多东西,而且几乎都是 return 相同的东西:"Unable to find (method used to find checkbox)"
一些尝试:
check("#accepts_fcra")
Capybara::ElementNotFound: Unable to find checkbox "#accepts_fcra"
find("#accepts_fcra").set true
Capybara::ElementNotFound: Unable to find css "#accepts_fcra"
within("div.checkbox") do
find(:xpath, "//input[@id='accepts_fcra']")
end
Capybara::ElementNotFound: Unable to find xpath "//input[@id='accepts_fcra']"
但是checkbox上面的2个类,“.check-group”和“.checkbox”都找到了,只是没有找到checkbox。想法?
想通了,试过这个:
find("accepts_fcra", :visible => false).click
它起作用了,元素是 'invisible',所以只需将它与查找一起传递并单击它就可以起作用。
visible: false
解决方案对我不起作用。
这是因为复选框被隐藏了,像这样
input[type="checkbox"]{
position: absolute;
opacity: 0;
cursor: pointer;
height: 0;
width: 0;
opacity:0;
}
并且使用了时髦的复选标记样式。
但是,点击标签对我有用
例如/
page.find(:xpath, "//label[@for='accepts_fcra']").click