I currently monkey patch `EventaullyPresent` to provide this kind of DOM 
waiting:

```ruby
div.when_dom_changes.a.click
```

It waits until DOM finishes chaning within `div` and then proceeds to `a`.

This is very useful to me. So far, there were no failures of the following JS 
code which implements this waiting. 

```js
var el = arguments[0]; // element which we'll look in for DOM change
window.WatirDOMReady = 0; // custom flag for DOM readiness

$(function () {
  window.WatirDOMReady += 1; // DOM is not ready

  var forceReady = _.once(function () {
    $(el).unbind('.wait_for_dom'); // unbind DOMSubtreeModified event from 
element
    window.WatirDOMReady -= 1; // DOM is ready
  });

  // bind DOMSubtreeModified event to element
  $(el).bind(
    'DOMSubtreeModified.wait_for_dom',
    _.debounce(forceReady, 300) // make sure it's not called many times
  );

  _.delay(forceReady, 3000);
});
```

After running this code on element, we can wait until

```ruby
browser.execute_script('return window.SeleniumDOMReady;').to_i == 0
```

However, it's browser support is limited (I'm only sure it works in Firefox) 
and it also depends on `underscore.js`. I can dig more and try to implement 
this with pure JS and check it's cross-browser compatibility (maybe find a way 
to extend it). But first, i want to be sure you guys think it makes sense to 
add it to Watir.

---
Reply to this email directly or view it on GitHub:
https://github.com/watir/watir-webdriver/issues/193
_______________________________________________
Wtr-development mailing list
[email protected]
http://rubyforge.org/mailman/listinfo/wtr-development

Reply via email to