watir-dom-wait
Watir extension which provides DOM-based waiting.
Installation
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
Usage
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
end
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
Using MutationObserver.
Note, that it also rescues Selenium::WebDriver::Error::StaleElementReferenceError
, Selenium::WebDriver::Error::JavascriptError
and Watir::Exception::UnknownObjectException
(only when its message contains Element not found in the cache - perhaps the page has changed since it was looked up
) when waits for DOM.
Contributors
Contributing
- Fork it
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create new Pull Request