Rails : Capybara::Webkit::ClickFailed, because of overlapping element

Capybara::Webkit::ClickFailed:
 Failed to click element /html/body/div[@id='wrapper']/div[@id='page-content-wrapper']/div/div/div/form[@id='signup']/div[@id='user_section']/div[7]/div[3]/div/button[@id='review_button'] because of overlapping element /html/body/div[8] at position 209, 718; 
 A screenshot of the page at the time of the failure has been written to /tmp/click_failed_S10458.png

 

The actual problem was; there was a link_tag (<a>) inside the <label> tag. So when I asked the capybara to click on the <label> it clicked on the  “Terms and Conditions” area and a popup appeared.

find('[for=agree_terms]').click

aaaaaaaaaaaaaa.png

 

To Solve this, I kept the link separate from the Label

 

Some useful links

http://stackoverflow.com/questions/34633269/wait-till-the-form-gets-submitted-in-capybara

https://robots.thoughtbot.com/automatically-wait-for-ajax-with-capybara

Advertisements

Rails : Capybara : When Checkboxes and Radio buttons are not found

There may come situation when you try to check(tick) the checkboxes via RSpec. using codes like

find('#agree_legal_guardian').click
find('#agree_terms').click

 

Problem was:

We have hidden the original checkbox and the fancy checkbox was being shown. Since the item was hidden Capybara was not able to find the element.

Solution

Instead of searching for hidden item, I triggered the click event on the Label for that Checkbox

within('.term-condition') do
  find('[for=agree_legal_guardian]').click
  find('[for=agree_terms]').click
end

Useful links

http://www.rubydoc.info/gems/capybara/1.0.0/Capybara/Node/Finders#find-instance_method

Rails : Capybara Webkit : Issue : Multiple JS events in single example

I recently moved from Selenium Web Driver to Thoughtbot’s Capybara Webkit as JS Driver for Capybara. The main reason is, webkit is super fast in running the test suite and its headless (no browser pops up ) .

Problem I faced

I was changing the option in select box and expecting the change in span’s content. Actually some sort of calculation should have been triggered. Webkit was not triggering the ‘change‘ event properly.

Continue reading

Capybara : RSpec : filling and assertion tips

To use helper method you need to visit some web page like

visit '/signup'

For Text fields

fill 'user[email]', with: 'john@example.com'
fill_in 'user[name]', with: 'John Smith'
fill_in 'user[email]', with: 'john@example.com'

For Select box

select 'Annually', from: 'subscription_type'
# The `Annually` is the text not the value attribute
# 'subscription_type' is name attribute
select 'Monthly', from: 'subscription_type'

Continue reading