Capybara无法选择复选框
我觉得我已经尝试了所有内容,但是我无法在应用程序中选择一个复选框。
我有两个看起来像这样的复选框。一个带有“奶酪”,一个带“泡菜”。它们是由Rails form_with的= form.check_box
自动生成的,
<input name="foods[]" type="hidden" value="0" autocomplete="off">
<input class="foodCheckbox" type="checkbox" value="cheese" name="food[]" id="food_cheese">
<a target="_blank" href="MyString">cheese</a>
现在要进行我的测试。我尝试了以下内容:
1。
check('food_cheese')
check('#food_cheese')
find("food_cheese").click
find("#food_cheese").click
find("food_cheese", visible: false).click
find("#food_cheese", visible: false).click
find(:css, "#food_cheese").set(true)
find(:css, "#food_cheese", visible: false).execute_script('this.checked = true')
该页面找到复选框。我无法单击标签,因为它是一个链接。当我做save_and_open
时,什么都不选择。如何选择复选框?
I feel like I have tried everything, but I cannot select a checkbox in my application.
I have two checkboxes that look like this. One with 'cheese' and one with 'pickles'. they're auto generated with Rails form_with's = form.check_box
<input name="foods[]" type="hidden" value="0" autocomplete="off">
<input class="foodCheckbox" type="checkbox" value="cheese" name="food[]" id="food_cheese">
<a target="_blank" href="MyString">cheese</a>
Now to my testing. I have tried the following:
1.
check('food_cheese')
check('#food_cheese')
find("food_cheese").click
find("#food_cheese").click
find("food_cheese", visible: false).click
find("#food_cheese", visible: false).click
find(:css, "#food_cheese").set(true)
find(:css, "#food_cheese", visible: false).execute_script('this.checked = true')
The page finds the checkboxes. I cannot click the label because it is a link. When I do save_and_open
nothing is selected. How do I select a checkbox?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以使用
查找(“#food_cheese”)。execute_script(“ this.click()”)
或
page.execute_script(“ document.queryselector)('#food_cheese')。 ”)
You can use
find("#food_cheese").execute_script("this.click()")
or
page.execute_script("document.querySelector('#food_cheese').click()")