Skip to content

Instantly share code, notes, and snippets.

@seeflanigan
Created December 6, 2011 19:56
Show Gist options
  • Select an option

  • Save seeflanigan/1439685 to your computer and use it in GitHub Desktop.

Select an option

Save seeflanigan/1439685 to your computer and use it in GitHub Desktop.
Element no longer connected to DOM
Found by Dima Kovalenko
Selenium specs which call "wait for element to be visible" fail on an "Element no longer connected to DOM" error.
The problem occurs when the div appears briefly, then goes away. If the loop exits after the div is already off the screen, the call to "wait for element to be visible times out, and causes the spec to fail.
This issue can be elusive, only failing intermittently because sometimes the loop exits quickly enough to avoid producing the error. The fact that the div is displayed then hidden was the key to identifying and solving this bug in our test.
--- a/features/support/env.rb
+++ b/features/support/env.rb
@@ -345,12 +345,15 @@ module Ajax
def wait_until_updated_element_is_visible(css_selector)
page.should have_css(css_selector)
- page.wait_until do
+ page.wait_until 20 do
+ visible = nil
if all(css_selector).empty?
- false
+ visible = false
else
- all(css_selector).first.visible?
+ visible = all(css_selector).first.visible?
end
+ puts "waiting.."
+ visible
end
end
end
@dimacus
Copy link

dimacus commented Dec 6, 2011

slightly less ugly diff

diff --git a/features/support/env.rb b/features/support/env.rb
index 54f753f..809b8d1 100644
--- a/features/support/env.rb
+++ b/features/support/env.rb
@@ -346,10 +346,11 @@ module Ajax
def wait_until_updated_element_is_visible(css_selector)
page.should have_css(css_selector)
page.wait_until do

  •  if all(css_selector).empty?
    
  •    false
    
  •  selectors = all(css_selector)
    
  •  if selectors.empty?
    
  •    return false
    
    else
  •    all(css_selector).first.visible?
    
  •    return selectors.first.visible?
    
    end
    end
    end

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment