Module: PageObject::Platforms::SeleniumWebDriver::Element
- Includes:
- Watir::Atoms
- Defined in:
- lib/page-object/platforms/selenium_webdriver/element.rb
Instance Method Summary collapse
-
#==(other) ⇒ Object
compare this element to another to determine if they are equal.
-
#attribute(attribute_name) ⇒ String?
Get the value of a the given attribute of the element.
-
#clear ⇒ Object
clear the contents of the element.
-
#exists? ⇒ Boolean
return true if an element exists.
-
#fire_event(event_name) ⇒ Object
Fire the provided event on the current element.
-
#focus ⇒ Object
Set the focus to the current element.
-
#parent ⇒ Object
find the parent element.
-
#right_click ⇒ Object
Click this element.
-
#send_keys(*args) ⇒ Object
Send keystrokes to this element.
-
#tag_name ⇒ String
Get the tag name of this element.
-
#text ⇒ String
Get the text for the element.
-
#value ⇒ String
Get the value of this element.
-
#visible? ⇒ Boolean
return true if an element is visible.
-
#wait_until(timeout = 5, message = nil, &block) ⇒ Object
Waits until the block returns true.
-
#when_not_visible(timeout = 5) ⇒ Object
Waits until the element is not visible.
-
#when_present(timeout = 5) ⇒ Object
Waits until the element is present.
-
#when_visible(timeout = 5) ⇒ Object
Waits until the element is visible.
Instance Method Details
#==(other) ⇒ Object
compare this element to another to determine if they are equal
47 48 49 |
# File 'lib/page-object/platforms/selenium_webdriver/element.rb', line 47 def ==(other) 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
90 91 92 |
# File 'lib/page-object/platforms/selenium_webdriver/element.rb', line 90 def attribute(attribute_name) element.attribute attribute_name end |
#clear ⇒ Object
clear the contents of the element
202 203 204 |
# File 'lib/page-object/platforms/selenium_webdriver/element.rb', line 202 def clear element.clear end |
#exists? ⇒ Boolean
return true if an element exists
22 23 24 |
# File 'lib/page-object/platforms/selenium_webdriver/element.rb', line 22 def exists? not element.nil? end |
#fire_event(event_name) ⇒ Object
Fire the provided event on the current element
97 98 99 100 101 102 |
# File 'lib/page-object/platforms/selenium_webdriver/element.rb', line 97 def fire_event(event_name) event_name = event_name.to_s.sub(/^on/, '').downcase script = "return (%s).apply(null, arguments)" % ATOMS.fetch(:fireEvent) bridge = element.instance_variable_get(:@bridge) bridge.executeScript(script, element, event_name) end |
#focus ⇒ Object
Set the focus to the current element
119 120 121 122 |
# File 'lib/page-object/platforms/selenium_webdriver/element.rb', line 119 def focus bridge = element.instance_variable_get(:@bridge) bridge.executeScript("return arguments[0].focus()", element) end |
#parent ⇒ Object
find the parent element
107 108 109 110 111 112 113 114 |
# File 'lib/page-object/platforms/selenium_webdriver/element.rb', line 107 def parent script = "return (%s).apply(null, arguments)" % ATOMS.fetch(:getParentElement) bridge = element.instance_variable_get(:@bridge) parent = bridge.executeScript(script, element) type = element.attribute(:type).to_s.downcase if parent.tag_name.to_sym == :input cls = ::PageObject::Elements.element_class_for(parent.tag_name, type) cls.new(parent, :platform => :selenium_webdriver) end |
#right_click ⇒ Object
Click this element
127 128 129 |
# File 'lib/page-object/platforms/selenium_webdriver/element.rb', line 127 def right_click element.context_click 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: ' '
195 196 197 |
# File 'lib/page-object/platforms/selenium_webdriver/element.rb', line 195 def send_keys(*args) element.send_keys(*args) end |
#tag_name ⇒ String
Get the tag name of this element
56 57 58 |
# File 'lib/page-object/platforms/selenium_webdriver/element.rb', line 56 def tag_name element.tag_name end |
#text ⇒ String
Get the text for the element
31 32 33 |
# File 'lib/page-object/platforms/selenium_webdriver/element.rb', line 31 def text element.text end |
#value ⇒ String
Get the value of this element
40 41 42 |
# File 'lib/page-object/platforms/selenium_webdriver/element.rb', line 40 def value element.attribute('value') end |
#visible? ⇒ Boolean
return true if an element is visible
15 16 17 |
# File 'lib/page-object/platforms/selenium_webdriver/element.rb', line 15 def visible? element.displayed? end |
#wait_until(timeout = 5, message = nil, &block) ⇒ Object
Waits until the block returns true
177 178 179 180 |
# File 'lib/page-object/platforms/selenium_webdriver/element.rb', line 177 def wait_until(timeout=5, =nil, &block) wait = Object::Selenium::WebDriver::Wait.new({:timeout => timeout, :message => }) wait.until &block end |
#when_not_visible(timeout = 5) ⇒ Object
Waits until the element is not visible
162 163 164 165 166 167 168 |
# File 'lib/page-object/platforms/selenium_webdriver/element.rb', line 162 def when_not_visible(timeout=5) wait = Object::Selenium::WebDriver::Wait.new({:timeout => timeout, :message => "Element not present in #{timeout} seconds"}) wait.until do not self.visible? end self end |
#when_present(timeout = 5) ⇒ Object
Waits until the element is present
136 137 138 139 140 141 142 |
# File 'lib/page-object/platforms/selenium_webdriver/element.rb', line 136 def when_present(timeout=5) wait = Object::Selenium::WebDriver::Wait.new({:timeout => timeout, :message => "Element not present in #{timeout} seconds"}) wait.until do self.exists? end self end |
#when_visible(timeout = 5) ⇒ Object
Waits until the element is visible
149 150 151 152 153 154 155 |
# File 'lib/page-object/platforms/selenium_webdriver/element.rb', line 149 def when_visible(timeout=5) wait = Object::Selenium::WebDriver::Wait.new({:timeout => timeout, :message => "Element not present in #{timeout} seconds"}) wait.until do self.visible? end self end |