Module: PageObject::Platforms::WatirWebDriver::Element

Defined in:
lib/page-object/platforms/watir_webdriver/element.rb

Instance Method Summary (collapse)

Instance Method Details

- (Object) ==(other)

compare this element to another to determine if they are equal



62
63
64
# File 'lib/page-object/platforms/watir_webdriver/element.rb', line 62

def ==(other)
  element == other.element
end

- (String?) attribute(attribute_name)

Get the value of a the given attribute of the element. Will return the current value, even if this has been modified after the page has been loaded. More exactly, this method will return the value of the given attribute, unless that attribute is not present, in which case the value of the property with the same name is returned. If neither value is set, nil is returned. The “style” attribute is converted as best can be to a text representation with a trailing semi-colon. The following are deemed to be “boolean” attributes, and will return either “true” or “false”:

async, autofocus, autoplay, checked, compact, complete, controls, declare, defaultchecked, defaultselected, defer, disabled, draggable, ended, formnovalidate, hidden, indeterminate, iscontenteditable, ismap, itemscope, loop, multiple, muted, nohref, noresize, noshade, novalidate, nowrap, open, paused, pubdate, readonly, required, reversed, scoped, seamless, seeking, selected, spellcheck, truespeed, willvalidate

Finally, the following commonly mis-capitalized attribute/property names are evaluated as expected:

class, readonly



105
106
107
# File 'lib/page-object/platforms/watir_webdriver/element.rb', line 105

def attribute(attribute_name)
  element.attribute_value attribute_name
end

- (Object) clear

clear the contents of the element



229
230
231
# File 'lib/page-object/platforms/watir_webdriver/element.rb', line 229

def clear
  element.clear
end

- (Object) double_click

double click the element



126
127
128
# File 'lib/page-object/platforms/watir_webdriver/element.rb', line 126

def double_click
  element.double_click
end

- (Boolean) exists?

return true if an element exists



21
22
23
# File 'lib/page-object/platforms/watir_webdriver/element.rb', line 21

def exists?
  element.exists?
end

- (Object) fire_event(event_name)

Fire the provided event on the current element



112
113
114
# File 'lib/page-object/platforms/watir_webdriver/element.rb', line 112

def fire_event(event_name)
  element.fire_event(event_name)
end

- (Object) flash

flash the element by temporarily changing the background color



28
29
30
# File 'lib/page-object/platforms/watir_webdriver/element.rb', line 28

def flash
  element.flash
end

- (Object) focus

Set the focus to the current element



143
144
145
# File 'lib/page-object/platforms/watir_webdriver/element.rb', line 143

def focus
  element.focus
end

- (Object) hover

hover over the element



119
120
121
# File 'lib/page-object/platforms/watir_webdriver/element.rb', line 119

def hover
  element.hover
end

- (String) html

Get the html for the element



46
47
48
# File 'lib/page-object/platforms/watir_webdriver/element.rb', line 46

def html
  element.html
end

- (Object) id

get the id of the element



236
237
238
# File 'lib/page-object/platforms/watir_webdriver/element.rb', line 236

def id
  element.id
end

- (Object) parent

find the parent element



133
134
135
136
137
138
# File 'lib/page-object/platforms/watir_webdriver/element.rb', line 133

def parent
  parent = element.parent
  type = element.type if parent.tag_name.to_sym == :input
  cls = ::PageObject::Elements.element_class_for(parent.tag_name, type)
  cls.new(parent, :platform => :watir_webdriver)
end

- (Object) scroll_into_view

Scroll until the element is viewable



243
244
245
# File 'lib/page-object/platforms/watir_webdriver/element.rb', line 243

def scroll_into_view
  element.wd.location_once_scrolled_into_view
end

- (Object) select_text(text)

Select the provided text



150
151
152
# File 'lib/page-object/platforms/watir_webdriver/element.rb', line 150

def select_text(text)
  element.select_text text
end

- (Object) send_keys(*args)

Send keystrokes to this element

Examples:

element.send_keys "foo"                     #=> value: 'foo'
element.send_keys "tet", :arrow_left, "s"   #=> value: 'test'
element.send_keys [:control, 'a'], :space   #=> value: ' '

See Also:

  • Selenium::WebDriver::Keys::KEYS


222
223
224
# File 'lib/page-object/platforms/watir_webdriver/element.rb', line 222

def send_keys(*args)
  element.send_keys(*args)
end

- (String) tag_name

Get the tag name of this element



71
72
73
# File 'lib/page-object/platforms/watir_webdriver/element.rb', line 71

def tag_name
  element.tag_name
end

- (String) text

Get the text for the element



37
38
39
# File 'lib/page-object/platforms/watir_webdriver/element.rb', line 37

def text
  element.text
end

- (String) value

Get the value of this element



55
56
57
# File 'lib/page-object/platforms/watir_webdriver/element.rb', line 55

def value
  element.value
end

- (Boolean) visible?

return true if an element is visible



14
15
16
# File 'lib/page-object/platforms/watir_webdriver/element.rb', line 14

def visible?
  element.present?
end

- (Object) wait_until(timeout = ::PageObject.default_element_wait, message = nil, &block)

Waits until the block returns true



205
206
207
# File 'lib/page-object/platforms/watir_webdriver/element.rb', line 205

def wait_until(timeout=::PageObject.default_element_wait, message=nil, &block)
  Object::Watir::Wait.until(timeout, message, &block)
end

- (Object) when_not_present(timeout = ::PageObject.default_element_wait)

Waits until the element is not present

timing out



170
171
172
# File 'lib/page-object/platforms/watir_webdriver/element.rb', line 170

def when_not_present(timeout=::PageObject.default_element_wait)
  element.wait_while_present(timeout)
end

- (Object) when_not_visible(timeout = ::PageObject.default_element_wait)

Waits until the element is not visible



191
192
193
194
195
196
# File 'lib/page-object/platforms/watir_webdriver/element.rb', line 191

def when_not_visible(timeout=::PageObject.default_element_wait)
  Object::Watir::Wait.while(timeout, "Element still visible after #{timeout} seconds") do
    visible?
  end
  self
end

- (Object) when_present(timeout = ::PageObject.default_element_wait)

Waits until the element is present



159
160
161
162
# File 'lib/page-object/platforms/watir_webdriver/element.rb', line 159

def when_present(timeout=::PageObject.default_element_wait)
  element.wait_until_present(timeout)
  self
end

- (Object) when_visible(timeout = ::PageObject.default_element_wait)

Waits until the element is visible



179
180
181
182
183
184
# File 'lib/page-object/platforms/watir_webdriver/element.rb', line 179

def when_visible(timeout=::PageObject.default_element_wait)
  Object::Watir::Wait.until(timeout, "Element was not visible in #{timeout} seconds") do
    visible?
  end
  self
end