Capybara没有方法错误

时间:2017-10-24 14:06:34

标签: ruby selenium testing automated-tests capybara

我想在标记字段中添加标记。要填写代码字段,我必须添加web: $JAVA_OPTS -Dserver.port=$PORT -jar target/dog-book-1.0.jar,或使用代码名称按Enter键,例如','。我为它写了这些步骤。

"Ezgi,"

我试着写这么多课程来填补这个领域,但那并没有奏效。在第11步中,我查看了这样的消息:

When(/^I enter "([^"]*)" on Label field$/) do |arg1|
    within('.x-anchor-form-item', :text=>'Label') do
        find('.x-tagfield-body').click
        fill_in('', :with=>arg1)
    end
    if page.has_css?('ul', :text=>arg1) then
        within('ul',:text=>arg1) do 
            find('li', :text=>arg1).click
        end 
    else
        within('.x-anchor-form-item', :text=>'Label') do
            find('.x-tagfield-body').native_send_keys(:enter)
        end
        within('.x-window-resizable', match: :first) do 
            find_all('a', :text=>'Save')[1].click
        end
        within('.x-anchor-form-item', :text=>'Label') do
            find('.x-form-text-wrap.x-form-text-wrap-default').click
            fill_in('', :with=>arg1)
        end
        within('ul',:text=>arg1) do 
            find('li', :text=>arg1).click
        end 
    end
end

有没有人对此案有任何想法?有人能帮助我吗?

1 个答案:

答案 0 :(得分:0)

Capybara没有方法native_send_keys。您复制的代码可能正在调用element.native.send_keys(...),但您也不应该调用它。只需在所需元素http://www.rubydoc.info/gems/capybara/Capybara/Node/Element#send_keys-instance_method上调用send_keys即可。在您的情况下将是

find('.x-tagfield-body').send_keys(:enter)

考虑到所提供的信息,这是否真的适用于您尝试与之交互的控件是不可能的,但它会解决这个问题的“无方法错误”。