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

#wait_until_present(timeout = nil) ⇒ Object

Waits until the element is present.

Examples:

browser.text_field(name: "new_user_first_name").wait_until_present

Parameters:

  • timeout (Fixnum) (defaults to: nil)

    seconds to wait before timing out

See Also:


223
224
225
226
227
# File 'lib/watir-webdriver/wait.rb', line 223

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

#wait_while_present(timeout = nil) ⇒ Object

Waits while the element is present.

Examples:

browser.text_field(name: "abrakadbra").wait_while_present

Parameters:

  • timeout (Fixnum) (defaults to: nil)

    seconds to wait before timing out

See Also:


241
242
243
244
245
246
247
# File 'lib/watir-webdriver/wait.rb', line 241

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::StaleElementReferenceError
  # it's not present
end

#when_enabled(timeout = nil) ⇒ Object

Waits until the element is enabled.

Examples:

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

Parameters:

  • timeout (Fixnum) (defaults to: nil)

    seconds to wait before timing out

See Also:


199
200
201
202
203
204
205
206
207
208
209
# File 'lib/watir-webdriver/wait.rb', line 199

def when_enabled(timeout = nil)
  timeout ||= Watir.default_timeout
  message = "waiting for #{selector_string} to become enabled"

  if block_given?
    Watir::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 (Fixnum) (defaults to: nil)

    seconds to wait before timing out

See Also:


175
176
177
178
179
180
181
182
183
184
185
# File 'lib/watir-webdriver/wait.rb', line 175

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