Class: Watir::Element

Inherits:
Object
  • Object
show all
Defined in:
lib/angular_webdriver/protractor/watir_patch.rb

Overview

Note the element class is different on master.

Instance Method Summary collapse

Instance Method Details

#allowAnimations(value = nil) ⇒ Object

Invoke protractor.allowAnimations with freshly located element and optional value.



115
116
117
118
# File 'lib/angular_webdriver/protractor/watir_patch.rb', line 115

def allowAnimations value=nil
  assert_exists
  driver.protractor.allowAnimations @element, value
end

#assert_enabledObject



98
99
100
# File 'lib/angular_webdriver/protractor/watir_patch.rb', line 98

def assert_enabled
  nil
end

#assert_existsObject

Ensure that the element exists by always relocating it Required to trigger waitForAngular. Caching the element here will break the Protractor sync feature so this must be @element = locate.



90
91
92
# File 'lib/angular_webdriver/protractor/watir_patch.rb', line 90

def assert_exists
  @element = locate
end

#assert_not_staleObject



94
95
96
# File 'lib/angular_webdriver/protractor/watir_patch.rb', line 94

def assert_not_stale
  nil
end

#clearObject

Watir doesn’t define a clear method on element so we have to provide one.



121
122
123
124
# File 'lib/angular_webdriver/protractor/watir_patch.rb', line 121

def clear
  assert_exists
  element_call { @element.clear }
end

#element_callObject

Always raise on stale element ref error. Prevents infinite retry loop.



60
61
62
63
64
# File 'lib/angular_webdriver/protractor/watir_patch.rb', line 60

def element_call
  yield
rescue Selenium::WebDriver::Error::StaleElementReferenceError
  raise
end

#evaluate(expression) ⇒ Object

Evaluate an Angular expression as if it were on the scope of the current element.

Parameters:

  • expression (String)

    The expression to evaluate.

Returns:

  • (Object)

    The result of the evaluation.



132
133
134
135
# File 'lib/angular_webdriver/protractor/watir_patch.rb', line 132

def evaluate expression
  assert_exists
  driver.protractor.evaluate @element, expression
end

#locateObject

avoid context lookup



109
110
111
# File 'lib/angular_webdriver/protractor/watir_patch.rb', line 109

def locate
  locator_class.new(@parent.wd, @selector, self.class.attribute_list).locate
end

#locatorObject

Return original selector. Method added for protractor compatibility



104
105
106
# File 'lib/angular_webdriver/protractor/watir_patch.rb', line 104

def locator
  @selector
end

#present?Boolean

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

rescue element not found

Returns:

  • (Boolean)

See Also:

  • Wait


145
146
147
148
149
150
151
# File 'lib/angular_webdriver/protractor/watir_patch.rb', line 145

def present?
  exists? && visible?
rescue Selenium::WebDriver::Error::NoSuchElementError, Selenium::WebDriver::Error::StaleElementReferenceError, UnknownObjectException
  # if the element disappears between the exists? and visible? calls,
  # consider it not present.
  false
end

#selected?Boolean

Returns:

  • (Boolean)


66
67
68
69
# File 'lib/angular_webdriver/protractor/watir_patch.rb', line 66

def selected?
  assert_exists
  element_call { @element.selected? }
end

#to_json(*args) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

required for watir otherwise execute_script will fail

e = browser.element(tag_name: ‘div’) driver.execute_script ‘return arguments.tagName’, e arguments.tagName“,”args“:}

Convert to a WebElement JSON Object for transmission over the wire.



82
83
84
85
# File 'lib/angular_webdriver/protractor/watir_patch.rb', line 82

def to_json(*args)
  assert_exists
  { ELEMENT: @element.ref }.to_json
end