0

我已经定义了一个 SitePrism 页面,它有一个带有选项的选择标签(在我的页面上创建一个下拉菜单)。

在我的黄瓜步骤中,我试图设置它,以便它从下拉菜单中选择一个选项,但似乎不可能这样做。

这是我的设置:

class ViewBudgetPage < SitePrism::Page
  set_url '/budget{/id}'

   element :date,            "input[name='cost_date']"
   element :description,     "input[name='cost_desc']"
   element :price,           "input[name='cost_price']"
   elements :categories,     "select[id='categories_list']"
   element :add_cost_button, "button[type='submit']"

在我的步骤中,我有:

When "I fill in the form to create a new cost" do
    @current_budget_page.date.set '1-Aug-2010'
    @current_budget_page.description.set 'some description'
    @current_budget_page.price.set '10'
    @current_budget_page.categories.select "Donations"
end

我的页面看起来像:

<div class='form-group'>
    <select class="form-control" id="categories_list"name='model_number'><option value='unselected'> Please select a category </option>   
<% @budget_wrapper.all_categories.each do |cat_name| %>
<option value='<%=cat_name%>'><%=cat_name%></option>
      <%end%>
     </select>
</div>

问题是在步骤中对元素调用“select”不起作用!它抱怨: ArgumentError Exception: wrong number of arguments (1 for 0)

不带参数调用 select 不会抱怨

@current_budget_page.categories.select

,但这不是我想要的。我认为这是从列表中获取第一个元素(默认值)。

我希望能够在我的步骤中说:从页面上的下拉菜单中选择一个特定元素。

请问有什么帮助吗?

谢谢。

4

1 回答 1

1

编辑:我的道歉:蒂姆穆里是正确的,我误读了这个问题。要选择第一个以外的项目请在评论中查看他的答案。

原来的:

您需要的两个步骤是:

  1. 找到您要查找的<option>元素(在本例中为第一个)。您可以#first<select>节点上执行此操作,因此:@current_budget_page.categories.first('option')
  2. 选择它。为此,您可以使用 [ #select_option][1]。

所以你想要的代码是:

@current_budget_page.categories.first('option').select_option
于 2015-11-24T00:43:39.783 回答