Far*_*ooq 3 checkbox visibility capybara selenium-webdriver
无法找到 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>
Run Code Online (Sandbox Code Playgroud)
现在我想用 ID“accepts_fcra”检查复选框。
我尝试了很多东西,但几乎都返回相同的东西:“无法找到(用于查找复选框的方法)”
一些尝试:
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']"
Run Code Online (Sandbox Code Playgroud)
但是checkbox上面的2个类,“.check-group”和“.checkbox”找到了,只是没有找到checkbox。想法?
想通了,试过这个:
find("accepts_fcra", :visible => false).click
Run Code Online (Sandbox Code Playgroud)
它起作用了,该元素是“不可见的”,因此只需将其与查找一起传递并单击即可工作。
| 归档时间: |
|
| 查看次数: |
4495 次 |
| 最近记录: |