Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/selenium/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Selenium 水豚-如何基于多个属性进行资格认证?_Selenium_Attributes_Capybara - Fatal编程技术网

Selenium 水豚-如何基于多个属性进行资格认证?

Selenium 水豚-如何基于多个属性进行资格认证?,selenium,attributes,capybara,Selenium,Attributes,Capybara,我可以用 expect(page).to have_selector("label.field_with_errors") 及 它们工作正常。 但是,我想检查它们在同一个字段上是否都是真的 我试过: expect(page).to have_selector("label[class='field_with_errors']:and([for='landing_zip_code'])") 及 但两者都不起作用。 第二次尝试时出错: Failure/Error: expect(page).to

我可以用

expect(page).to have_selector("label.field_with_errors")

它们工作正常。
但是,我想检查它们在同一个字段上是否都是真的

我试过:

expect(page).to
have_selector("label[class='field_with_errors']:and([for='landing_zip_code'])")

但两者都不起作用。 第二次尝试时出错:

Failure/Error: expect(page).to
have_selector("label[class='field_with_errors']") &&
have_selector('landing_zip_code')
expected to find css "landing_zip_code" but there were no matches
我也试过了

expect(find("label[class='field_with_errors']")).to
have_attribute('for=landing_zip_code')
但是得到

Failure/Error: expect(find("label[class='field_with_errors']")).
to have_attribute('for=landing_zip_code')
expected #<Capybara::Node::Element:0x00003b5de90> to respond to `has_attribute?`
# ./spec/features/quote_spec.rb:65:in `block (3 levels) in <top (required)>'
但是得到

Failure/Error: expect(find("label[class='field_with_errors']")['for=landing_zip_code']).to be
expected nil to evaluate to true
在此(我是OP)中,我可以使用“
”类和“
#
”标识符来执行此操作,即

expect(page).to
have_selector("label.field_with_errors[for='landing_zip_code']")
但是,我也想知道如何检测除了类和id之外的其他多个属性(我是OP),我可以使用“
”类和“
#
”标识符来实现这一点,即

expect(page).to
have_selector("label.field_with_errors[for='landing_zip_code']")

但是,我也想知道如何检测除了class和id之外还有其他多个属性

您尝试过下面的方法吗

expect(page).to have_selector("label[for='landing_zip_code']" && "label.field_with_errors")

你试过下面的方法吗

expect(page).to have_selector("label[for='landing_zip_code']" && "label.field_with_errors")

expect(查找(“label[class='field\u without\u errors']['for=landing\u zip\u code'])).to-be
expect(查找(“label[class='field\u without\u errors']['for=landing\u zip\u code'])。要做到这一点,
您可以以类似的方式继续检查属性:
label.field without\u errors[for='landing\u-zip\u-code']
。这就是你要问的吗?谢谢。您可以用类似的方式继续检查属性:
label.field\u带有错误[for='landing\u zip\u code'][other\u attr=value1][one\u more\u attr=value2]
。这就是你要问的吗?谢谢。虽然这可能回答了作者的问题,但它缺少一些解释性的词语和/或文档链接。如果没有一些短语,原始代码片段就没有多大帮助。你也会发现这很有帮助。请编辑您的答案。虽然这可能回答了作者的问题,但它缺少一些解释性词语和/或文档链接。如果没有一些短语,原始代码片段就没有多大帮助。你也会发现这很有帮助。请编辑您的答案。
expect(page).to have_selector("label[for='landing_zip_code']" && "label.field_with_errors")