Module: Watir::ElementExtensions

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

Overview

This assumes that Element#visible? is defined

Defined Under Namespace

Classes: WhenPresentDecorator

Instance Method Summary collapse

Instance Method Details

#present?Boolean

Returns true if the element exists and is visible on the page

Returns:

  • (Boolean)


35
36
37
# File 'lib/watir-classic/element_extensions.rb', line 35

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

#wait_until_present(timeout = 60) ⇒ Object



60
61
62
# File 'lib/watir-classic/element_extensions.rb', line 60

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

#wait_while_present(timeout = 60) ⇒ Object



64
65
66
# File 'lib/watir-classic/element_extensions.rb', line 64

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

#when_present(timeout = 60) ⇒ Object

Waits until the element is present.

Optional argument:

timeout   -  seconds to wait before timing out (default: 60)

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


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

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