Module: Watir::EventuallyPresent

Included in:
Element, Window
Defined in:
lib/watir-webdriver/wait.rb

Overview

Convenience methods for things that eventually become present.

Includers should implement a public #present? and a (possibly private) #selector_string method.

Instance Method Summary (collapse)

Instance Method Details

- (Object) wait_until_present(timeout = 30)

Waits until the element is present.

Parameters:

  • timeout (Integer) (defaults to: 30)

    seconds to wait before timing out

See Also:



130
131
132
133
# File 'lib/watir-webdriver/wait.rb', line 130

def wait_until_present(timeout = 30)
  message = "waiting for #{selector_string} to become present"
  Watir::Wait.until(timeout, message) { present? }
end

- (Object) wait_while_present(timeout = 30)

Waits while the element is present.

Parameters:

  • timeout (Integer) (defaults to: 30)

    seconds to wait before timing out

See Also:



144
145
146
147
148
149
# File 'lib/watir-webdriver/wait.rb', line 144

def wait_while_present(timeout = 30)
  message = "waiting for #{selector_string} to disappear"
  Watir::Wait.while(timeout, message) { present? }
rescue Selenium::WebDriver::Error::ObsoleteElementError
  # it's not present
end

- (Object) when_present(timeout = 30)

Waits until the element is present.

Example:

browser.button(:id, 'foo').when_present.click
browser.div(:id, 'bar').when_present { |div| ... }
browser.p(:id, 'baz').when_present(60).text

Parameters:

  • timeout (Integer) (defaults to: 30)

    seconds to wait before timing out

See Also:



110
111
112
113
114
115
116
117
118
119
# File 'lib/watir-webdriver/wait.rb', line 110

def when_present(timeout = 30)
  message = "waiting for #{selector_string} to become present"

  if block_given?
    Watir::Wait.until(timeout, message) { present? }
    yield self
  else
    WhenPresentDecorator.new(self, timeout, message)
  end
end