Class: Watir::Element

Inherits:
Object
  • Object
show all
Defined in:
lib/watir/dom/elements/element.rb

Constant Summary collapse

DOM_WAIT_JS =
File.read("#{File.dirname(__FILE__)}/../extensions/js/waitForDom.js").freeze

Instance Method Summary collapse

Instance Method Details

#dom_changed?(delay: 1.1) ⇒ Boolean

Returns true if DOM is changed within the element.

Examples:

Wait until DOM is changed inside element with default delay

browser.div(id: 'test').wait_until(&:dom_changed?).click

Wait until DOM is changed inside element with default delay

browser.div(id: 'test').wait_until do |element|
  element.dom_changed?(delay: 5)
end

Parameters:

  • delay (Integer, Float) (defaults to: 1.1)

    how long to wait for DOM modifications to start

Returns:

  • (Boolean)


19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/watir/dom/elements/element.rb', line 19

def dom_changed?(delay: 1.1)
  element_call do
    begin
      script_timeout = driver.manage.timeouts.script_timeout
      driver.manage.timeouts.script_timeout = delay + Watir::DOM::Wait.minimum_script_timeout
      driver.execute_async_script(DOM_WAIT_JS, wd, delay)
    rescue Selenium::WebDriver::Error::JavascriptError => error
      # sometimes we start script execution before new page is loaded and
      # in rare cases ChromeDriver throws this error, we just swallow it and retry
      retry if error.message.include?('document unloaded while waiting for result')
      raise
    ensure
      driver.manage.timeouts.script_timeout = script_timeout
    end
  end
end