appfolio / ae_page_objects

Page Objects for Capybara
MIT License
28 stars 9 forks source link

Reload elements on StaleElementReferenceError #202

Closed tlconnor closed 6 years ago

tlconnor commented 6 years ago

This PR fixes an issue where in some conditions Selenium::WebDriver::Error::StaleElementReferenceError is thrown.

The problem occurs when a test stores a deeply nested instance of AePageObjects::Element in a variable, reloads the page, and then continues to use that element. Because the element references a capybara node that is obsolete the error above can occur.

The solution is to detect this scenario and then traverse back up to the root node of the tree and reload elements.

See https://github.com/appfolio/ae_page_objects/pull/202/files#diff-941de1d6909262810f79a64585c03622R624 for an example test case that reproduces the problem.