未找到水豚+硒+ rspec +元素

时间:2013-06-17 13:32:02

标签: selenium ruby-on-rails-3.2 selenium-webdriver capybara

我使用capybara + selenium + rspec来测试我的应用程序。我有一个页面,其中没有一个元素被ajax或javascript(hide / show / toggle)操纵。当我尝试使用

在页面上提交表单时
click_button 'Save'

它给我一个错误,说明找不到元素。我使用'save_and_open_page'来查看html内容,一切看起来都很好。页面需要向下滚动访问按钮。只是为了好奇,我改变了按钮的位置,这样我就不需要滚动页面,可以在页面加载时直接访问按钮。在后一种情况下,我的水豚规格运行良好。我无法在这种奇怪的水豚行为背后找出问题的根源。问题是,在我的大多数视图中,我可以在滚动页面后访问我的提交按钮。我该如何避免上述问题?

宝石版本是

capybara 2.1.0
selenium 0.2.10
selenium-client 1.2.18
selenium-webdriver 2.33.0

水豚代码

fill_in 'user_name', :with => 'Abc Xyz'
fill_in 'user_phone', :with => '58743653'
fill_in 'user_password', :with => 'prasad'
fill_in 'user_password_confirmation', :with => 'prasad'
fill_in 'user_designation', :with => 'Programmer'
page.execute_script "window.scroll(0,10000)"
#find_by_id('save_user').native.send_key(:enter)
sleep 20
page.execute_script("$('form.of-setup').submit()") #current hack to make it work
#click_button 'save my profile'
current_url.include?("registrations/terms/#{@user.invitation_token}").should == true

如果我取消注释“保存我的个人资料”按钮,则会出现错误

Failure/Error: click_button 'save my profile'
Capybara::ElementNotFound:
Unable to find button "save my profile"

如果我取消注释'发送键'行,则会出现错误

Failure/Error: find_by_id('save_user').native.send_key(:enter)
Capybara::ElementNotFound:
Unable to find id "save_user"

haml代码为

...# additional view code
.optional-area
  .container
    .row
      .span2
         
      .span14
        %fieldset
          = f.text_field :designation, :help => 'Type a job title', :placeholder => "(optional; like Senior Design Engineer)", :label => "Title"
          = f.text_area :street, :rows => "2", :help => "Type the company's street number and name", :placeholder => "(optional; like 1111)", :label => "Street Address"
          = f.text_field :city, :help => 'Type a city name', :placeholder => "(optional; like San Jose)"
          = f.text_field :state, :help => 'Type a stae or province name or abbreviation', :placeholder => "(optional; like CA)", :label => "State/Province"
          = f.text_field :postal_code, :help => 'Type a postal code', :placeholder => "(optional; like 95131)"
    .row
      .span12.offset4
        = f.submit "save my profile", :class => "btn primary verylarge toUpperCase", :disable_with => "SAVE MY PROFILE", :id => 'save_user'
        = link_to 'cancel', root_path, :class => "cancel-link of-link of-cancel toUpperCase quickhelp", 'data-placement' => "above", :title => "Abandon the action"
...#additional view code

0 个答案:

没有答案