Class: Watir::WhenPresentDecorator

Inherits:
Object
  • Object
show all
Defined in:
lib/watir-webdriver/extensions/wait.rb

Overview

Wraps an Element so that any subsequent method calls are put on hold until the element is present (exists and is visible) on the page.

Instance Method Summary collapse

Constructor Details

#initialize(element, timeout) ⇒ WhenPresentDecorator

Returns a new instance of WhenPresentDecorator



55
56
57
58
# File 'lib/watir-webdriver/extensions/wait.rb', line 55

def initialize(element, timeout)
  @element = element
  @timeout = timeout
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(m, *args, &block) ⇒ Object



60
61
62
63
64
65
66
67
68
# File 'lib/watir-webdriver/extensions/wait.rb', line 60

def method_missing(m, *args, &block)
  unless @element.respond_to?(m)
    raise NoMethodError, "undefined method `#{m}' for #{@element.inspect}:#{@element.class}"
  end

  Watir::Wait.until(@timeout) { @element.present? }

  @element.__send__(m, *args, &block)
end