gpt4 book ai didi

ruby - capybara field.has_css?匹配器

转载 作者:数据小太阳 更新时间:2023-10-29 07:13:52 25 4
gpt4 key购买 nike

我在 MiniTest::SpecCapybara 中使用以下规范:

find_field('Email').must_have_css('[autofocus]')

检查名为“电子邮件”的字段是否具有 autofocus 属性。 doc说如下:

has_css?(path, options = {})

Checks if a given CSS selector is on the page or current node.

据我了解,字段“Email”是一个节点,因此调用 must_have_css 绝对有效!我做错了什么?

最佳答案

通过 Jonas Nicklas 得到了答案:

No, it shouldn't work. has_css? will check if any of the descendants of the element match the given CSS. It will not check the element itself. Since the autofocus property is likely on the email field itself, has_css? will always return false in this case.

You might try:

find_field('Email')[:autofocus].should be_present

this can also be done with XPath, but I can't recall the syntax off the top of my head.


我的解决方案:

find_field('Email')[:autofocus].must_equal('autofocus')

关于ruby - capybara field.has_css?匹配器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8282399/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com