水豚检查 HTML 类和 ID
我目前正在尝试找到这个元素并让水豚验证它是否存在。有一个元素出现,我正在使用 page.should have_css 来查看该元素是否存在。
<i class="ui-grid-icon-cancel" ui-grid-one-bind-aria-label="aria.removeFilter" aria-label="Remove Filter"> </i>
我目前正在尝试访问 ui-grid-icon-cancel 并验证它是否存在。这是我用来验证它的代码。
page.should have_css('class#ui-grid-icon-cancel')
我还能做什么来解决这个问题。
我期望使用水豚验证 CSS 元素。
I'm currently trying to find this element and have capybara validate that it's there. There's an element that shows up and I'm using page.should have_css to see if this element is there.
<i class="ui-grid-icon-cancel" ui-grid-one-bind-aria-label="aria.removeFilter" aria-label="Remove Filter"> </i>
I'm currently trying to get to the ui-grid-icon-cancel and validate that it's there. Here is the code I'm using to validate it.
page.should have_css('class#ui-grid-icon-cancel')
What else can I do to fix this.
I'm expecting to validate the CSS element using capybara.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
关于所需 CSS 选择器的所有其他答案都是正确的,但是如果您收到有关
should
未定义的错误,那么您可能没有正确安装 RSpec,或者您的项目具有should 语法已禁用 - https://relishapp.com/rspec/rspec-expectations/docs/syntax-configuration。 RSpec 4 中默认会禁用
should
语法,此时任何新代码都不应该使用它。相反,您应该使用expect
语法。假设您已正确安装 RSpec,以下任何操作都应该有效,具体取决于您要验证的内容All the other answers are correct about the needed CSS selectors, however if you're getting errors about
should
being undefined then you either haven't installed RSpec correctly or your project has theshould
syntax disabled - https://relishapp.com/rspec/rspec-expectations/docs/syntax-configuration. Theshould
syntax is going to be disabled by default in RSpec 4, and any new code really shouldn't be using it at this point. Instead you should be using theexpect
syntax. Any of the following should work, assuming you have RSpec properly installed, depending on exactly what you're trying to verify您是否尝试过
page.should have_css('.ui-grid-icon-cancel')
。查找类元素时,您需要使用句点表示法,而不是明确地输入“类”一词。`
Did you try
page.should have_css('.ui-grid-icon-cancel')
. When looking for a class element, you need to use the notation of a period rather then explicitly putting the word "class".`
您可以使用以下任一定位器策略:
css_selector 使用 class 属性的值:
css_selector 使用 aria-label 属性的值:
You can use either of the following locator strategies:
css_selector using value of class attribute:
css_selector using value of aria-label attribute: