{"issue":{"state":"closed","created_at":"2011-12-14T13:52:53Z","updated_at":"2011-12-15T12:05:40Z","user":{"gravatar_id":"522c66f4c4bc46cc4df007018e2505e6","id":2376,"url":"https://api.github.com/users/bastien","avatar_url":"https://secure.gravatar.com/avatar/522c66f4c4bc46cc4df007018e2505e6?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-140.png","login":"bastien"},"comments":3,"body":"I have a cucumber step that check the number of elements corresponding to a given css rule on a page:\r\n\r\n```ruby\r\nThen /^I should see ([0-9]+) \"([^\"]*)\"$/ do |count, selector|\r\n  elements = page.all(selector)\r\n  elements.size.should == count.to_i\r\nend\r\n```\r\nHere's where I use it:\r\n\r\n```gherkin\r\n  @javascript\r\n  Scenario: Creating pages\r\n    When I go to the pages list\r\n    And I press \"Add pages\"\r\n    Then I should see 10 \".page\"\r\n```\r\nClicking the \"Add pages\" button will make a ajax request and the response will add 10 '.page' elements.\r\n\r\nSince I upgraded to 1.1.2 from 1.0.1 this scenario fails. Adding a ```sleep 1 ``` fixes the problem, but it's obviously not a good solution.\r\n\r\nI've observed the same problem with a dialog windows. This code now fails because it's executed before any dialog has appeared on the page:\r\n\r\n```ruby\r\nThen /^I accept the confirm dialog$/ do\r\n  page.driver.browser.switch_to.alert.accept\r\nend\r\n```","assignee":null,"id":2551632,"number":566,"pull_request":{"patch_url":null,"html_url":null,"diff_url":null},"labels":[],"title":"Cabybara 1.1.* not waiting for Javascript to finish executing","html_url":"https://github.com/jnicklas/capybara/issues/566","closed_at":"2011-12-14T16:24:28Z","milestone":null,"url":"https://api.github.com/repos/jnicklas/capybara/issues/566"},"action":"created","comment":{"created_at":"2011-12-15T12:05:40Z","updated_at":"2011-12-15T12:05:40Z","user":{"gravatar_id":"6c469749d725177dd2837d806c769cd4","id":134,"url":"https://api.github.com/users/jnicklas","avatar_url":"https://secure.gravatar.com/avatar/6c469749d725177dd2837d806c769cd4?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-140.png","login":"jnicklas"},"body":"It's because `page.all` returns instantly, whereas `has_selector` waits for the result to appear. In Capy 1.1 we no longer block when AJAX requests happen, instead we keep trying to find the correct content. However you need to tell Capybara what that content is. If you're using `page.all` it has no idea what you want to do with that later on, so it just returns the results as they are right now.","id":3160182,"url":"https://api.github.com/repos/jnicklas/capybara/issues/comments/3160182"}}