在Capybara中找到DIV标签?

发布于 2025-02-03 16:02:18 字数 311 浏览 1 评论 0原文

我目前正在尝试查找此选项卡并单击它。我正在尝试找到一种单击此按钮的更简单的方法。在我的代码中,我尝试使用查找命令,并且无法找到此选项卡。

<div role="tab" aria-disabled="false" aria-selected="true" class="ant-tabs-tab-active ant-tabs-tab">Animals</div>

代码:

find('tab[div=Animals]').click

不确定我在做什么错。

I'm currently trying to find this tab and click on it. I'm trying to find a easier way of clicking on this button. In my code, I tried to use find command and it's unable to find this tab.

<div role="tab" aria-disabled="false" aria-selected="true" class="ant-tabs-tab-active ant-tabs-tab">Animals</div>

Code:

find('tab[div=Animals]').click

Not sure what I'm doing wrong.

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

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

发布评论

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

评论(1

冬天旳寂寞 2025-02-10 16:02:18

看来您需要更多地研究CSS选择器。 “动物”是文本内容,CSS不能提供查询文本内容的方法。在Capybara中,您可以使用text选项通过其文本内容过滤匹配节点,从而将有效的CSS与text> text过滤相结合

find('div[role="tab"]', text: 'Animals').click 

,或者

find('div.ant-tabs-tab', text: 'Animals').click

是单击该元素

注意的方法:我会推荐 https://flukeout.github.io/ 使用CSS选择器。

It looks like you need to study CSS selectors a bit more. 'Animals' is text content and CSS does not provide a way to query on text content. In Capybara you can use the text option to filter matching nodes by their text content so combining valid CSS with the text filter like

find('div[role="tab"]', text: 'Animals').click 

or

find('div.ant-tabs-tab', text: 'Animals').click

would be ways of clicking on that element

Note: I would recommend https://flukeout.github.io/ to learn what you can and can't do with CSS selectors.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文