【问题标题】:capybara & cucumber css locator not found未找到水豚和黄瓜 css 定位器
【发布时间】:2013-07-22 17:08:54
【问题描述】:

我是黄瓜和水豚的新手,我对以下错误感到困惑:

   When I click the "Search" button    # features/step_definitions/web_steps.rb:9
  Unable to find button #<Capybara::Element tag="button"> (Capybara::ElementNotFound)
  ./features/step_definitions/web_steps.rb:11:in `/^I click the "([^"]*)" button$/'
  features/search.feature:9:in `When I click the "Search" button'

在我的功能中,我有:

When I click the "Search" button

我的步骤如下:

When /^I click the "([^"]*)" button$/ do |button_text|
  button_text = find('#gbqfb')
  click_button button_text
end

我已经尝试过 'click(button_text) 和 click_link 方法。我在想它可能很明显,我没有看到。我正在尝试找到按钮元素的 css 定位器,然后单击该元素。我认为不需要更改正则表达式,因为无论如何我都在更改“button_text”局部变量。还是我?

【问题讨论】:

    标签: selenium cucumber capybara


    【解决方案1】:

    您可以使用firstfind 方法,然后像这样设置点击

    first('.page a', :text => '2').click
    find('.page a', :text => '2').click
    

    为了你的黄瓜

    When /^I click the "([^"]*)" button$/ do |button_text|
      first('.page a', :text => "#{button_text}").click
    end
    

    When /^I click the "([^"]*)" button$/ do |button_text|
      find('.page a', :text => "#{button_text}").click
    end
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-02-24
      • 1970-01-01
      相关资源
      最近更新 更多