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(opts = nil) ⇒ 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
Clear this element.
-
#click ⇒ Object
Click the element.
-
#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.
-
#style(prop) ⇒ Object
Get the value of the given CSS property.
-
#submit ⇒ Object
Submit this element.
-
#tag_name ⇒ String
Get the tag name of this element.
-
#text ⇒ String
Get the text content of this element.
-
#to_json(*args) ⇒ 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
12 13 14 |
# File 'lib/selenium/webdriver/common/element.rb', line 12 def initialize(bridge, id) @bridge, @id = bridge, id end |
Instance Method Details
#==(other) ⇒ Object Also known as: eql?
20 21 22 |
# File 'lib/selenium/webdriver/common/element.rb', line 20 def ==(other) other.kind_of?(self.class) && bridge.elementEquals(self, other) end |
#as_json(opts = nil) ⇒ 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/
243 244 245 |
# File 'lib/selenium/webdriver/common/element.rb', line 243 def as_json(opts = nil) { :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
73 74 75 |
# File 'lib/selenium/webdriver/common/element.rb', line 73 def attribute(name) bridge.getElementAttribute @id, name end |
#clear ⇒ Object
Clear this element
110 111 112 |
# File 'lib/selenium/webdriver/common/element.rb', line 110 def clear bridge.clearElement @id end |
#click ⇒ Object
Click the element
33 34 35 |
# File 'lib/selenium/webdriver/common/element.rb', line 33 def click bridge.clickElement @id end |
#displayed? ⇒ Boolean
Is the element displayed?
140 141 142 |
# File 'lib/selenium/webdriver/common/element.rb', line 140 def displayed? bridge.isElementDisplayed @id end |
#enabled? ⇒ Boolean
Is the element enabled?
120 121 122 |
# File 'lib/selenium/webdriver/common/element.rb', line 120 def enabled? bridge.isElementEnabled @id end |
#hash ⇒ Object
25 26 27 |
# File 'lib/selenium/webdriver/common/element.rb', line 25 def hash @id.hash ^ @bridge.hash end |
#inspect ⇒ Object
16 17 18 |
# File 'lib/selenium/webdriver/common/element.rb', line 16 def inspect '#<%s:0x%x id=%s>' % [self.class, hash*2, @id.inspect] end |
#location ⇒ WebDriver::Point
Get the location of this element.
173 174 175 |
# File 'lib/selenium/webdriver/common/element.rb', line 173 def location bridge.getElementLocation @id end |
#location_once_scrolled_into_view ⇒ WebDriver::Point
Determine an element’s location on the screen once it has been scrolled into view.
183 184 185 |
# File 'lib/selenium/webdriver/common/element.rb', line 183 def location_once_scrolled_into_view bridge.getElementLocationOnceScrolledIntoView @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
222 223 224 |
# File 'lib/selenium/webdriver/common/element.rb', line 222 def ref @id end |
#selected? ⇒ Boolean
Is the element selected?
130 131 132 |
# File 'lib/selenium/webdriver/common/element.rb', line 130 def selected? bridge.isElementSelected @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: ' '
101 102 103 |
# File 'lib/selenium/webdriver/common/element.rb', line 101 def send_keys(*args) bridge.sendKeysToElement @id, Keys.encode(args) end |
#size ⇒ WebDriver::Dimension
Get the size of this element
193 194 195 |
# File 'lib/selenium/webdriver/common/element.rb', line 193 def size bridge.getElementSize @id end |
#style(prop) ⇒ Object
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.
163 164 165 |
# File 'lib/selenium/webdriver/common/element.rb', line 163 def style(prop) bridge.getElementValueOfCssProperty @id, prop end |
#submit ⇒ Object
Submit this element
148 149 150 |
# File 'lib/selenium/webdriver/common/element.rb', line 148 def submit bridge.submitElement @id end |
#tag_name ⇒ String
Get the tag name of this element
43 44 45 |
# File 'lib/selenium/webdriver/common/element.rb', line 43 def tag_name bridge.getElementTagName @id end |
#text ⇒ String
Get the text content of this element
83 84 85 |
# File 'lib/selenium/webdriver/common/element.rb', line 83 def text bridge.getElementText @id 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.
Convert to a WebElement JSON Object for transmission over the wire.
233 234 235 |
# File 'lib/selenium/webdriver/common/element.rb', line 233 def to_json(*args) MultiJson.encode as_json end |