Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7558689
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T12:26:09+00:00 2026-05-30T12:26:09+00:00

I am using Watir-webdriver 0.5.3. Before with versions circa 0.4.x this was never trouble:

  • 0

I am using Watir-webdriver 0.5.3. Before with versions circa 0.4.x this was never trouble:

 while  $browser.div(:class =>  /^expander$/).exists?   
  $browser.div(:class => /^expander$/).click; sleep 1.5
 end

The click causes some javascript to execute that changes the class for the div that was clicked, expanding a treeview control. The objective of the script is to keep expanding nodes until there are none left unexpanded.

I am frequently getting “Element is no longer attached to the DOM” on the .exists? line, which is esp. troubling, because the reason I began using .exists? extensively was to avoid such errors that immediately crash the script in the first place.

visually I do observe the expansion almost right away after the .click, and if I pause things right there, Firebug does confirm that the div with only class=’expander’ had been replaced with a div in its place with class=’expander hasChildren expanded’, and only that div.

The error seems to be coming up from webdriver.

Has anyone else had this problem or recommend workarounds?

In an earlier question I needed to switch to the /^expander$/ form to match exactly that class exclusively, after the new watir-webdriver behavior changed.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T12:26:10+00:00Added an answer on May 30, 2026 at 12:26 pm

    What about this?

    while  $browser.div(:class =>  /^expander$/).exists?
      count = $browser.divs(:class => 'expander hasChildren expanded').size   
      $browser.div(:class => /^expander$/).click
      $browser.wait_until{$browser.div(:class => 'expander hasChildren expanded', :index => count).exists?}
     end
    

    The other approach I have used where actions are causing things to go away, is get a count, and then work by index, from the last item back towards the first, that way the ‘next thing’ you are addressing should still exist. That can be more reliable than always addressing ‘first one’ where your prior action just removed ‘first one’. If expanding things opens up new ‘expander’ classes then you might have to do this in waves, where you end up expanding the first tier, then the second, etc till you see no more of them to expand. it might mean making a method to expand all currently visible expanders, then checking when it is done to see if there are any visible expanders, and if so, call the method again.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using WATIR to control browser, but there is page that never fully loads
Using Watir I have been able to isolate this button element: <BUTTON id=authButton class=commandButton
I am using watir-webdriver and am attempting to check the background-color of an HTML
I would like to set a text field with watir-webdriver using css selectors to
I'm using Watir to do some automated testing for a website. This particular test
Using Watir-Webdriver, how can I automate the output of all the elements in an
I'm using watir-webdriver with chrome to automate my tests and I'm kinda stuck now.
So I'm using Watir WebDriver with both Firefox and Chrome. Chrome is much faster
I'm looking at Watir-Webdriver to manipulate a browser. In particular, I'd like to open
I am using watir-webdriver to scrape from a page with nested table based layout.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.