浏览Capybara的清单?

发布于 2025-02-13 12:01:26 字数 574 浏览 0 评论 0原文

我有一个下拉菜单。我希望Capybara通过它找到特定元素,然后单击它。我目前正在尝试在子句中进行一个,并在列表中迭代并找到此元素:“ cow_poop”

<li role="option" unselectable="on" title="Cow_poop" class="ant-select-dropdown-menu-item ant-select-dropdown-menu-item-selected" aria-selected="true" style="user-select: none;">Cow_pop</li>

这是我要执行的代码。

find('div.ant-select-dropdown-menu-item-selected', text: 'Cow_poop').click

但是,这给了我这个错误:

 Capybara::ElementNotFound:
       Unable to find css "div.ant-select-dropdown-menu-item-selected"

I have a drop down menu. I want capybara to go through it and find the specific element and click on it. I'm currently trying to do a within clause and having it iterate through the list and find this element: "Cow_poop"

<li role="option" unselectable="on" title="Cow_poop" class="ant-select-dropdown-menu-item ant-select-dropdown-menu-item-selected" aria-selected="true" style="user-select: none;">Cow_pop</li>

This is the code that I'm trying to do.

find('div.ant-select-dropdown-menu-item-selected', text: 'Cow_poop').click

However it's giving me this error:

 Capybara::ElementNotFound:
       Unable to find css "div.ant-select-dropdown-menu-item-selected"

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

合久必婚 2025-02-20 12:01:26

它不是&lt; div&gt;,而是&lt; li&gt;元素。

您有效的代码线将是:

find('li.ant-select-dropdown-menu-item-selected', title: 'Cow_poop').click

替代:

find('li.ant-select-dropdown-menu-item-selected[title=Cow_poop]').click

It's not a <div> but a <li> element.

Your effective line of code will be:

find('li.ant-select-dropdown-menu-item-selected', title: 'Cow_poop').click

Alternative:

find('li.ant-select-dropdown-menu-item-selected[title=Cow_poop]').click
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文