Module: Watir::ElementExtensions

Included in:
Alert, Element, Window
Defined in:
lib/watir-classic/element_extensions.rb

Overview

This module adds some helper methods for asynchronous testing.

Instance Method Summary collapse

Instance Method Details

#present?Boolean

Returns true when element exists and is visible, false otherwise.

Returns:

  • (Boolean)

    true when element exists and is visible, false otherwise.



31
32
33
# File 'lib/watir-classic/element_extensions.rb', line 31

def present?
  exists? && visible? rescue false
end

#wait_until_present(timeout = 60) ⇒ Object

Wait until element is present before continuing.

Raises:



62
63
64
# File 'lib/watir-classic/element_extensions.rb', line 62

def wait_until_present(timeout = 60)
  Watir::Wait.until(timeout) { self.present? }
end

#wait_while_present(timeout = 60) ⇒ Object

Wait while element is present before continuing.

Raises:



70
71
72
# File 'lib/watir-classic/element_extensions.rb', line 70

def wait_while_present(timeout = 60)
  Watir::Wait.while(timeout) { self.present? }
end

#when_present(timeout = 60) ⇒ Object

Waits until the element is present before calling its methods.

Examples:

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

Parameters:

  • timeout (Fixnum) (defaults to: 60)

    seconds to wait before timing out.

Raises:



49
50
51
52
53
54
55
56
# File 'lib/watir-classic/element_extensions.rb', line 49

def when_present(timeout = 60)
  if block_given?
    Watir::Wait.until(timeout) { self.present? }
    yield self
  else
    return WhenPresentDecorator.new(self, timeout)
  end
end