Module: Watir::EventuallyPresent

Included in:
Alert, Element, Window
Defined in:
lib/watir/legacy_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

#when_enabled(timeout = nil) ⇒ Object

Waits until the element is enabled.

Examples:

browser.button(name: "new_user_button_2").when_enabled.click

Parameters:

  • timeout (Integer) (defaults to: nil)

    seconds to wait before timing out

See Also:


107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
# File 'lib/watir/legacy_wait.rb', line 107

def when_enabled(timeout = nil)
  msg = '#when_enabled'
  repl_msg = 'wait_until(&:enabled?)'
  Watir.logger.deprecate msg, repl_msg, ids: [:when_enabled]

  timeout ||= Watir.default_timeout
  message = "waiting for #{selector_string} to become enabled"

  if block_given?
    Wait.until(timeout, message) { enabled? }
    yield self
  else
    WhenEnabledDecorator.new(self, timeout, message)
  end
end

#when_present(timeout = nil) ⇒ Object

Waits until the element is present.

Examples:

browser.text_field(name: "new_user_first_name").when_present.click
browser.text_field(name: "new_user_first_name").when_present { |field| field.set "Watir" }
browser.text_field(name: "new_user_first_name").when_present(60).text

Parameters:

  • timeout (Integer) (defaults to: nil)

    seconds to wait before timing out

See Also:


79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
# File 'lib/watir/legacy_wait.rb', line 79

def when_present(timeout = nil)
  msg = '#when_present'
  repl_msg = '#wait_until_present if a wait is still needed'
  Watir.logger.deprecate msg, repl_msg, ids: [:when_present]

  timeout ||= Watir.default_timeout
  message = "waiting for #{selector_string} to become present"

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