diff --git a/lib/capybara/node/element.rb b/lib/capybara/node/element.rb index ed87350e..ec20a44f 100644 --- a/lib/capybara/node/element.rb +++ b/lib/capybara/node/element.rb @@ -22,10 +22,14 @@ module Capybara # class Element < Base - def initialize(session, base, parent, selector) + def initialize(session, base, parent, query) super(session, base) @parent = parent - @selector = selector + @query = query + end + + def allow_reload! + @allow_reload = true end ## @@ -186,8 +190,10 @@ module Capybara end def reload - reloaded = parent.reload.first(@selector.name, @selector.locator, @selector.options) - @base = reloaded.base if reloaded + if @allow_reload + reloaded = parent.reload.first(@query.name, @query.locator, @query.options) + @base = reloaded.base if reloaded + end self end diff --git a/lib/capybara/node/finders.rb b/lib/capybara/node/finders.rb index 289ef168..76f1e29d 100644 --- a/lib/capybara/node/finders.rb +++ b/lib/capybara/node/finders.rb @@ -24,7 +24,7 @@ module Capybara # @raise [Capybara::ElementNotFound] If the element can't be found before time expires # def find(*args) - synchronize { all(*args).find! } + synchronize { all(*args).find! }.tap(&:allow_reload!) end ## diff --git a/lib/capybara/node/simple.rb b/lib/capybara/node/simple.rb index f4c94912..96c3509e 100644 --- a/lib/capybara/node/simple.rb +++ b/lib/capybara/node/simple.rb @@ -122,6 +122,10 @@ module Capybara yield # simple nodes don't need to wait end + def allow_reload! + # no op + end + def all(*args) query = Capybara::Query.new(*args) elements = native.xpath(query.xpath).map do |node| diff --git a/lib/capybara/spec/public/test.js b/lib/capybara/spec/public/test.js index 07a126f5..4ef1e6cd 100644 --- a/lib/capybara/spec/public/test.js +++ b/lib/capybara/spec/public/test.js @@ -40,4 +40,9 @@ $(function() { $('#reload-me').replaceWith('
'); }, 250) }); + $('#reload-list').click(function() { + setTimeout(function() { + $('#the-list').html('This is text
This is a draggable element.
@@ -17,16 +17,16 @@It should be dropped here.
- +
@@ -44,6 +44,14 @@
+ Fetch new list! +