黄瓜:找到带有标签文本X的输入? [英] Cucumber: find the input with label text X?

查看:746
本文介绍了黄瓜:找到带有标签文本X的输入?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Cucumber,我试图创建一个这样的步骤:

 然后我应该看到在业务名称输入中

我想将业务名称输入定义为



这里是我到目前为止的步骤:

 然后/ ^我应该在([^] *)输入$ / do | content,labeltext | 
#不确定要放在这里
end

在jQuery中,对于带有该文本的标签,查看其for属性,并找到具有该id的输入,但我目前在Cucumber中看到的唯一的选择器是:

  within(input:nth-​​child(#{pos.to_i})

  page.should have_content('foo')

解决方案

查看



您可以使用 find_field(labeltext)

 #示例:
#'我应该在问候输入中看到Howdy '(Greeting是标签文本)
然后/ ^我应该在([^] *)输入$ / do | content,labeltext |
find_field(#{labeltext})。value.should == content
end


In Cucumber, I'm trying to create a step like this:

Then I should see "Example business name" in the "Business name" input

I'd like the "Business name" input to be defined as "the input whose label has text "Business name."

Here's what I've got on the step so far:

Then /^I should see "([^"]*)" in the "([^"]*)" input$/ do |content, labeltext|
  # Not sure what to put here
end

In jQuery, I'd look for the label with that text, look at its "for" attribute, and find the input with that id. But the only selectors I've seen so far in Cucumber are these:

within("input:nth-child(#{pos.to_i}")

and

page.should have_content('foo')

Can anybody suggest a solution using the Webrat / Capybara selector syntax?

解决方案

Figured it out

You can find an input by its label text using find_field(labeltext).

# Example:
# 'I should see "Howdy" in the "Greeting" input' ("Greeting" is the label text)
Then /^I should see "([^"]*)" in the "([^"]*)" input$/ do |content, labeltext|
    find_field("#{labeltext}").value.should == content
end

这篇关于黄瓜:找到带有标签文本X的输入?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆