在Capybara中找到DIV标签?
我目前正在尝试查找此选项卡并单击它。我正在尝试找到一种单击此按钮的更简单的方法。在我的代码中,我尝试使用查找命令,并且无法找到此选项卡。
<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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
看来您需要更多地研究CSS选择器。 “动物”是文本内容,CSS不能提供查询文本内容的方法。在Capybara中,您可以使用
text
选项通过其文本内容过滤匹配节点,从而将有效的CSS与text> text
过滤相结合,或者
是单击该元素
注意的方法:我会推荐 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 thetext
filter likeor
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.