Module: Watir::EventuallyPresent

Included in:
Alert, 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 = nil)

Waits until the element is present.

Examples:

browser.button(:id => 'foo').wait_until_present

See Also:



171
172
173
174
175
# File 'lib/watir-webdriver/wait.rb', line 171

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

- (Object) wait_while_present(timeout = nil)

Waits while the element is present.

Examples:

browser.button(:id => 'foo').wait_while_present

See Also:



189
190
191
192
193
194
195
# File 'lib/watir-webdriver/wait.rb', line 189

def wait_while_present(timeout = nil)
  timeout ||= Watir.default_timeout
  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 = nil)

Waits until the element is present.

Examples:

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

See Also:



147
148
149
150
151
152
153
154
155
156
157
# File 'lib/watir-webdriver/wait.rb', line 147

def when_present(timeout = nil)
  timeout ||= Watir.default_timeout
  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