watir-dom-wait Build Status Gem Version

Watir extension which provides DOM-based waiting.


Add this line to your application's Gemfile:

gem 'watir-dom-wait'

And then execute:

$ bundle

Or install it yourself as:

$ gem install watir-dom-wait


Require to monkey patch Watir::Element instance:

require 'watir-dom-wait'

Simple DOM waiting:

browser.div(class: 'test').wait_until_dom_changed

With element returned:

browser.div(class: 'test').when_dom_changed.a(class: 'link').click

With passing block:

browser.div(class: 'test').when_dom_changed do |div|
  div.a(class: 'link').click

With timeout of 10 seconds:

browser.div(class: 'test').when_dom_changed(timeout: 10).a(class: 'link').click

With interval of checking for subtree modifications of 2 seconds:

browser.div(class: 'test').when_dom_changed(interval: 2).a(class: 'link').click

With 5 seconds delay of how long to waiting for DOM to start modifying:

browser.div(class: 'test').when_dom_changed(delay: 5).a(class: 'link').click

Timeouts can also be specified statically:

Watir::Dom::Wait.timeout  = 1
Watir::Dom::Wait.delay    = 1
Watir::Dom::Wait.interval = 0.15

How it works

By attaching DOMSubtreeModified event to element. It's supported in all major browsers (except Presto-powered Opera).

Note, that it also rescues Selenium::WebDriver::Error::StaleElementReferenceError when waits for DOM.



  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request