gpt4 book ai didi

selenium-webdriver - 无法找到 capybara 的复选框

转载 作者:行者123 更新时间:2023-12-04 07:53:42 29 4
gpt4 key购买 nike

无法找到 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”的复选框。

我尝试了很多东西,几乎都返回相同的东西:“无法找到(用于查找复选框的方法)”

一些尝试:

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']"

但是复选框上面的2个类,“.check-group”和“.checkbox”找到了,只是找不到复选框。想法?

最佳答案

想通了,试过这个:

find("accepts_fcra", :visible => false).click

它起作用了,该元素是“不可见的”,因此只需将其与查找一起传递并单击即可使其起作用。

关于selenium-webdriver - 无法找到 capybara 的复选框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35874291/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com