Class: Selenium::WebDriver::Element
- Inherits:
-
Object
- Object
- Selenium::WebDriver::Element
- Includes:
- SearchContext
- Defined in:
- lib/selenium/webdriver/common/element.rb
Constant Summary
Constants included from SearchContext
Instance Method Summary collapse
- #==(other) ⇒ Object (also: #eql?)
-
#as_json ⇒ Object
private
For Rails 3 - jonathanjulian.com/2010/04/rails-to_json-or-as_json/.
-
#attribute(name) ⇒ String?
(also: #[])
Get the value of a the given attribute of the element.
-
#clear ⇒ Object
If this element is a text entry element, this will clear the value.
-
#click ⇒ Object
Click this element.
-
#css_value(prop) ⇒ Object
(also: #style)
Get the value of the given CSS property.
-
#displayed? ⇒ Boolean
Is the element displayed?.
-
#enabled? ⇒ Boolean
Is the element enabled?.
- #hash ⇒ Object
-
#initialize(bridge, id) ⇒ Element
constructor
private
Creates a new Element.
- #inspect ⇒ Object
-
#location ⇒ WebDriver::Point
Get the location of this element.
-
#location_once_scrolled_into_view ⇒ WebDriver::Point
Determine an element’s location on the screen once it has been scrolled into view.
-
#ref ⇒ Object
private
for SearchContext and execute_script.
-
#selected? ⇒ Boolean
Is the element selected?.
-
#send_keys(*args) ⇒ Object
(also: #send_key)
Send keystrokes to this element.
-
#size ⇒ WebDriver::Dimension
Get the size of this element.
-
#submit ⇒ Object
Submit this element.
-
#tag_name ⇒ String
Get the tag name of the element.
-
#text ⇒ String
Get the text content of this element.
-
#to_json ⇒ Object
private
Convert to a WebElement JSON Object for transmission over the wire.
Methods included from SearchContext
Constructor Details
#initialize(bridge, id) ⇒ Element
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.
Creates a new Element
31 32 33 34 |
# File 'lib/selenium/webdriver/common/element.rb', line 31 def initialize(bridge, id) @bridge = bridge @id = id end |
Instance Method Details
#==(other) ⇒ Object Also known as: eql?
40 41 42 |
# File 'lib/selenium/webdriver/common/element.rb', line 40 def ==(other) other.is_a?(self.class) && ref == other.ref end |
#as_json ⇒ 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.
For Rails 3 - jonathanjulian.com/2010/04/rails-to_json-or-as_json/
294 295 296 |
# File 'lib/selenium/webdriver/common/element.rb', line 294 def as_json(*) @id.is_a?(Hash) ? @id : {:ELEMENT => @id} end |
#attribute(name) ⇒ String? Also known as: []
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
117 118 119 |
# File 'lib/selenium/webdriver/common/element.rb', line 117 def attribute(name) bridge.element_attribute self, name end |
#clear ⇒ Object
If this element is a text entry element, this will clear the value. Has no effect on other elements. Text entry elements are INPUT and TEXTAREA elements.
Note that the events fired by this event may not be as you’d expect. In particular, we don’t fire any keyboard or mouse events. If you want to ensure keyboard events are fired, consider using #send_keys with the backspace key. To ensure you get a change event, consider following with a call to #send_keys with the tab key.
160 161 162 |
# File 'lib/selenium/webdriver/common/element.rb', line 160 def clear bridge.clear_element @id end |
#click ⇒ Object
Click this element. If this causes a new page to load, this method will attempt to block until the page has loaded. At this point, you should discard all references to this element and any further operations performed on this element will raise a StaleElementReferenceError unless you know that the element and the page will still be present. If click() causes a new page to be loaded via an event or is done by sending a native event then the method will not wait for it to be loaded and the caller should verify that a new page has been loaded.
There are some preconditions for an element to be clicked. The element must be visible and it must have a height and width greater then 0.
Equivalent to:
driver.action.click(element)
73 74 75 |
# File 'lib/selenium/webdriver/common/element.rb', line 73 def click bridge.click_element @id end |
#css_value(prop) ⇒ Object Also known as: style
Get the value of the given CSS property
Note that shorthand CSS properties (e.g. background, font, border, border-top, margin, margin-top, padding, padding-top, list-style, outline, pause, cue) are not returned, in accordance with the DOM CSS2 specification - you should directly access the longhand properties (e.g. background-color) to access the desired values.
213 214 215 |
# File 'lib/selenium/webdriver/common/element.rb', line 213 def css_value(prop) bridge.element_value_of_css_property @id, prop end |
#displayed? ⇒ Boolean
Is the element displayed?
190 191 192 |
# File 'lib/selenium/webdriver/common/element.rb', line 190 def displayed? bridge.element_displayed? @id end |
#enabled? ⇒ Boolean
Is the element enabled?
170 171 172 |
# File 'lib/selenium/webdriver/common/element.rb', line 170 def enabled? bridge.element_enabled? @id end |
#hash ⇒ Object
45 46 47 |
# File 'lib/selenium/webdriver/common/element.rb', line 45 def hash @id.hash ^ @bridge.hash end |
#inspect ⇒ Object
36 37 38 |
# File 'lib/selenium/webdriver/common/element.rb', line 36 def inspect format '#<%s:0x%x id=%s>', self.class, hash * 2, @id.inspect end |
#location ⇒ WebDriver::Point
Get the location of this element.
224 225 226 |
# File 'lib/selenium/webdriver/common/element.rb', line 224 def location bridge.element_location @id end |
#location_once_scrolled_into_view ⇒ WebDriver::Point
Determine an element’s location on the screen once it has been scrolled into view.
234 235 236 |
# File 'lib/selenium/webdriver/common/element.rb', line 234 def location_once_scrolled_into_view bridge.element_location_once_scrolled_into_view @id end |
#ref ⇒ 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.
for SearchContext and execute_script
273 274 275 |
# File 'lib/selenium/webdriver/common/element.rb', line 273 def ref @id end |
#selected? ⇒ Boolean
Is the element selected?
180 181 182 |
# File 'lib/selenium/webdriver/common/element.rb', line 180 def selected? bridge.element_selected? @id end |
#send_keys(*args) ⇒ Object Also known as: send_key
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: ' '
145 146 147 |
# File 'lib/selenium/webdriver/common/element.rb', line 145 def send_keys(*args) bridge.send_keys_to_element @id, Keys.encode(args) end |
#size ⇒ WebDriver::Dimension
Get the size of this element
244 245 246 |
# File 'lib/selenium/webdriver/common/element.rb', line 244 def size bridge.element_size @id end |
#submit ⇒ Object
Submit this element
198 199 200 |
# File 'lib/selenium/webdriver/common/element.rb', line 198 def submit bridge.submit_element @id end |
#tag_name ⇒ String
Get the tag name of the element.
87 88 89 |
# File 'lib/selenium/webdriver/common/element.rb', line 87 def tag_name bridge.element_tag_name @id end |
#text ⇒ String
Get the text content of this element
127 128 129 |
# File 'lib/selenium/webdriver/common/element.rb', line 127 def text bridge.element_text @id end |
#to_json ⇒ 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.
Convert to a WebElement JSON Object for transmission over the wire.
284 285 286 |
# File 'lib/selenium/webdriver/common/element.rb', line 284 def to_json(*) JSON.generate as_json end |