1

I m using capybara + selenium + rspec to test my application. I have a page, none of whose elements are manipulated by ajax or javascript(hide/show/toggle). When ever i try to submit the form on the page using

click_button 'Save'

it gives me an error stating element not found. i used 'save_and_open_page' to view the html contents and everything looks fine. the page needs to be scrolled down the access the button. Just for curiosity, i changed the button position so that i dont need to scroll the page and can directly access the button when the page is loaded. In the later case, my capybara spec runs fine. I m not able to derive the root of the problem behind this weird behavior of capybara. The issue is, in most of my views, my submit buttons can be accessed after scrolling the page. How do i avoid the above problem?

the gem versions are

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

the capybara code

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

if i uncomment the 'save my profile' button, it gives error as

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

and if i uncomment the 'send key' line, it gives error as

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

the haml code is as

...# 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
4

0 回答 0