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

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

Instance Method Summary collapse

Instance Method Details

#==(other) ⇒ Object

compare this element to another to determine if they are equal



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

def ==(other)
  other.is_a? self.class and element == other.element
end

#attribute(attribute_name) ⇒ String?

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



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

def attribute(attribute_name)
  element.attribute_value attribute_name
end

#centreObject

Get centre coordinates of element



292
293
294
295
296
# File 'lib/page-object/platforms/watir_webdriver/element.rb', line 292

def centre
  location = element.wd.location
  size = element.wd.size
  {'y' => (location['y'] + (size['height']/2)), 'x' => (location['x'] + (size['width']/2))}
end

#clearObject

clear the contents of the element



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

def clear
  element.clear
end

#double_clickObject

double click the element



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

def double_click
  element.double_click
end

#exists?Boolean

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

#fire_event(event_name) ⇒ Object

Fire the provided event on the current element



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

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

#flashObject

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

#focusObject

Set the focus to the current element



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

def focus
  element.focus
end

#heightObject

Get height of element



278
279
280
# File 'lib/page-object/platforms/watir_webdriver/element.rb', line 278

def height
  element.wd.size['height']
end

#hoverObject

hover over the element



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

def hover
  element.hover
end

#htmlString

Get the html for the element



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

def html
  element.html
end

#idObject

get the id of the element



250
251
252
# File 'lib/page-object/platforms/watir_webdriver/element.rb', line 250

def id
  element.id
end

#locationObject

location of element (x, y)



264
265
266
# File 'lib/page-object/platforms/watir_webdriver/element.rb', line 264

def location
  element.wd.location
end

#parentObject

find the parent element



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

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 => @platform.class::PLATFORM_NAME)
end

#right_clickObject

Right click on an element



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

def right_click
  element.right_click
end

#scroll_into_viewObject

Scroll until the element is viewable



257
258
259
# File 'lib/page-object/platforms/watir_webdriver/element.rb', line 257

def scroll_into_view
  element.wd.location_once_scrolled_into_view
end

#select_text(text) ⇒ Object

Select the provided text



157
158
159
# File 'lib/page-object/platforms/watir_webdriver/element.rb', line 157

def select_text(text)
  element.select_text text
end

#send_keys(*args) ⇒ Object

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


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

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

#sizeObject

size of element (width, height)



271
272
273
# File 'lib/page-object/platforms/watir_webdriver/element.rb', line 271

def size
  element.wd.size
end

#tag_nameString

Get the tag name of this element



78
79
80
# File 'lib/page-object/platforms/watir_webdriver/element.rb', line 78

def tag_name
  element.tag_name
end

#textString

Get the text for the element



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

def text
  element.text
end

#valueString

Get the value of this element



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

def value
  element.value
end

#visible?Boolean

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

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

Waits until the block returns true



219
220
221
# File 'lib/page-object/platforms/watir_webdriver/element.rb', line 219

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

#when_not_present(timeout = ::PageObject.default_element_wait) ⇒ Object

Waits until the element is not present

timing out



184
185
186
# File 'lib/page-object/platforms/watir_webdriver/element.rb', line 184

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

#when_not_visible(timeout = ::PageObject.default_element_wait) ⇒ Object

Waits until the element is not visible



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

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

#when_present(timeout = ::PageObject.default_element_wait) ⇒ Object

Waits until the element is present



173
174
175
176
# File 'lib/page-object/platforms/watir_webdriver/element.rb', line 173

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

#when_visible(timeout = ::PageObject.default_element_wait) ⇒ Object

Waits until the element is visible



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

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

#widthObject

Get width of element



285
286
287
# File 'lib/page-object/platforms/watir_webdriver/element.rb', line 285

def width
  element.wd.size['width']
end