lundi 28 mars 2016

Capybara/Cucumber In Ruby: stop searching when no more elements exist

The website I'm testing has a bunch of selected filters (picture for context). I'm looping through all of them and closing them like so:

When /^each (.+) is clicked$/ do |element|
    page.all("#{element}").each do |element|
            element.click
    end
end

This code clicks the close button and closes all the open filters. The problem I'm having, is when I get to the end of the filters, it keeps looking and throws this error:

stale element reference: element is not attached to the page document
        (Session info: chrome=49.0.2623.87)
        (Driver info: chromedriver=2.20.353124 (035346203162d32c80f1dce587c8154a1efa0c3b),platform=Mac OS X 10.10.5 x86_64) (Selenium::WebDriver::Error::StaleElementReferenceError)
      ./features/step_definitions/ux_steps.rb:22:in `block (2 levels) in <top (required)>'
      ./features/step_definitions/ux_steps.rb:21:in `/^each (.+) is clicked$/'
      features/ux.feature:16:in `When each span is clicked'

Any ideas on how to stop the search once the list of items is empty? All help is appreciated!

Aucun commentaire:

Enregistrer un commentaire