我无法获得Capybara查找复选框元素。水豚(poltergeist)无法找到复选框
我已经尝试了所有的常用方法:
find_field
check
find
click_on
这是因为如果该元素是不存在的。如果我选择父元素,看它的innerHTML复选框包括:
(byebug) all(:css, '.checkbox.form-group').last['innerHTML']
\n <input type=\"checkbox\" id=\"google_agreed_to_terms_at\" value=\"1\" required=\"true\" ng-model=\"agreed_to_terms\" required-notification=\"Please agree to the terms and conditions\" class=\"ng-pristine ng-untouched ng-empty ng-invalid ng-invalid-required\" bs-validation=\"\">\
,但选择的子元素它不存在:
(byebug) all(:css, '.checkbox.form-group').last.all :xpath, './*'
[#<Capybara::Node::Element tag="label"
path="//HTML[1]/BODY[1]/DIV[2]/DIV[1]/DIV[2]/FORM[1]/DIV[1]/LABEL[1]">]
我觉得我快要疯掉。
这里的(从save_and_open_page
复制)
<div class="checkbox form-group">
<input type="checkbox" id="agreed_to_terms_at" value="1" required="true" ng-model="agreed_to_terms" required-notification="Please agree to the terms and conditions" class="ng-pristine ng-untouched ng-empty ng-invalid ng-invalid-required" bs-validation="">
<label class="label-light" for="agreed_to_terms_at">
I have read and agree to the terms</label>
</div>
我想,也许是钢轨产生不符合标准的HTML略微相关的代码,所以我去了手写的复选框,但它并没有帮助。
这是怎么回事吗?
你就不能添加在您的spec_helper:'Capybara.ignore_hidden_elements = FALSE'? (为了避免在你需要的时候使用你的解决方案) – fabersky
我曾考虑过这样做,因为这不是我第一次发现它很麻烦,但我明白水豚的价值,要求你说“是的,我知道用户看不到这一点,但我仍然想改变它“,以避免隐藏元素被规范意外操纵提供错误传递的用例。 – ChristopherJ
使用触发器('click')或将Capybara.ignore_hidden_elements设置为false应该是测试应用程序时的最后解决方案(罚款如果是抓取站点),因为它们执行用户从未执行过的操作 –