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.
What about this?
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.