Class: Selenium::WebDriver::Element
Relationships & Source Files | |
Super Chains via Extension / Inclusion / Inheritance | |
Instance Chain:
self,
TakesScreenshot ,
SearchContext
|
|
Inherits: | Object |
Defined in: | rb/lib/selenium/webdriver/common/element.rb |
Constant Summary
-
ELEMENT_KEY =
# File 'rb/lib/selenium/webdriver/common/element.rb', line 23'element-6066-11e4-a52e-4f735466cecf'
SearchContext
- Included
Class Method Summary
-
.new(bridge, id) ⇒ Element
constructor
Internal use only
Internal use only
Creates a new
Element
.
Instance Attribute Summary
-
#displayed? ⇒ Boolean
readonly
Is the element displayed?
-
#enabled? ⇒ Boolean
readonly
Is the element enabled?
-
#selected? ⇒ Boolean
readonly
Is the element selected?
- #bridge readonly private
- #selectable? ⇒ Boolean readonly private
Instance Method Summary
- #==(other) (also: #eql?)
-
#[](name)
Alias for #attribute.
-
#accessible_name ⇒ String
Gets the computed WAI-ARIA label of element.
-
#all
element.all(class: ‘bar’).
-
#aria_role ⇒ String
Gets the computed WAI-ARIA role of element.
-
#attribute(name) ⇒ String?
(also: #[])
This method attempts to provide the most likely desired current value for the attribute of the element, even when that desired value is actually a JavaScript property.
-
#clear
If this element is a text entry element, this will clear the value.
-
#click
Click this element.
-
#css_value(prop)
(also: #style)
Get the value of the given CSS property.
-
#dom_attribute(name) ⇒ String?
Gets the value of a declared HTML attribute of this element.
-
#eql?(other)
Alias for #==.
-
#first
element.first(id: ‘foo’).
- #hash
- #inspect
-
#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.
-
#property(name) ⇒ String?
Gets the value of a JavaScript property of this element This will return the current value, even if this has been modified after the page has been loaded.
-
#rect ⇒ WebDriver::Rectangle
Get the dimensions and coordinates of this element.
-
#send_key(*args)
Alias for #send_keys.
-
#send_keys(*args)
(also: #send_key)
Send keystrokes to this element.
-
#shadow_root ⇒ WebDriver::ShadowRoot
Returns the shadow root of an element.
-
#size ⇒ WebDriver::Dimension
Get the size of this element.
-
#style(prop)
Alias for #css_value.
-
#submit
Submit this element.
-
#tag_name ⇒ String
Get the tag name of the element.
-
#text ⇒ String
Get the text content of this element.
- #screenshot private
-
#as_json
Internal use only
Internal use only
For Rails 3 - jonathanjulian.com/2010/04/rails-to_json-or-as_json/.
- #ref Internal use only Internal use only
-
#to_json
Internal use only
Internal use only
Convert to a WebElement JSON Object for transmission over the wire.
TakesScreenshot
- Included
#save_screenshot | Save a PNG screenshot of the viewport to the given path. |
#screenshot_as | Return a PNG screenshot in the given format as a string. |
SearchContext
- Included
#find_element | Find the first element matching the given arguments. |
#find_elements | Find all elements matching the given arguments. |
#extract_args |
Constructor Details
.new(bridge, id) ⇒ Element
Creates a new Element
Instance Attribute Details
#bridge (readonly, private)
[ GitHub ]# File 'rb/lib/selenium/webdriver/common/element.rb', line 381
attr_reader :bridge
#displayed? ⇒ Boolean
(readonly)
Is the element displayed?
# File 'rb/lib/selenium/webdriver/common/element.rb', line 252
def displayed? bridge.element_displayed? self end
#enabled? ⇒ Boolean
(readonly)
Is the element enabled?
# File 'rb/lib/selenium/webdriver/common/element.rb', line 232
def enabled? bridge.element_enabled? @id end
#selectable? ⇒ Boolean
(readonly, private)
[ GitHub ]
#selected? ⇒ Boolean
(readonly)
Is the element selected?
# File 'rb/lib/selenium/webdriver/common/element.rb', line 242
def selected? bridge.element_selected? @id end
Instance Method Details
#==(other) Also known as: #eql?
[ GitHub ]#[](name)
Alias for #attribute.
# File 'rb/lib/selenium/webdriver/common/element.rb', line 347
alias [] attribute
#accessible_name ⇒ String
Gets the computed WAI-ARIA label of element.
# File 'rb/lib/selenium/webdriver/common/element.rb', line 179
def accessible_name bridge.element_aria_label @id end
#all
element.all(class: ‘bar’)
# File 'rb/lib/selenium/webdriver/common/element.rb', line 342
alias all find_elements
#aria_role ⇒ String
Gets the computed WAI-ARIA role of element
# File 'rb/lib/selenium/webdriver/common/element.rb', line 169
def aria_role bridge.element_aria_role @id end
#as_json
For Rails 3 - jonathanjulian.com/2010/04/rails-to_json-or-as_json/
# File 'rb/lib/selenium/webdriver/common/element.rb', line 375
def as_json(*) @id.is_a?(Hash) ? @id : {ELEMENT_KEY => @id} end
#attribute(name) ⇒ String
?
Also known as: #[]
This method attempts to provide the most likely desired current value for the attribute of the element, even when that desired value is actually a JavaScript property. It is implemented with a custom JavaScript atom. To obtain the exact value of the attribute or property, use #dom_attribute or #property methods respectively.
More exactly, this method will return the value of the property with the given name, if it exists. If it does not, then the value of the attribute with the given name is returned. If neither exists, null is returned.
The “style” attribute is converted as best can be to a text representation with a trailing semicolon.
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:
When the value of “class” is requested, the “className” property is returned. When the value of “readonly” is requested, the “readOnly” property is returned.
# File 'rb/lib/selenium/webdriver/common/element.rb', line 126
def attribute(name) bridge.element_attribute self, name end
#clear
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.
# File 'rb/lib/selenium/webdriver/common/element.rb', line 222
def clear bridge.clear_element @id end
#click
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)
# File 'rb/lib/selenium/webdriver/common/element.rb', line 76
def click bridge.click_element @id end
#css_value(prop) 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.
# File 'rb/lib/selenium/webdriver/common/element.rb', line 275
def css_value(prop) bridge.element_value_of_css_property @id, prop end
#dom_attribute(name) ⇒ String
?
Gets the value of a declared HTML attribute of this element.
As opposed to the #attribute method, this method only returns attributes declared in the element’s HTML markup.
If the attribute is not set, nil is returned.
# File 'rb/lib/selenium/webdriver/common/element.rb', line 145
def dom_attribute(name) bridge.element_dom_attribute @id, name end
#eql?(other)
Alias for #==.
# File 'rb/lib/selenium/webdriver/common/element.rb', line 46
alias eql? ==
#first
element.first(id: ‘foo’)
# File 'rb/lib/selenium/webdriver/common/element.rb', line 336
alias first find_element
#hash
[ GitHub ]# File 'rb/lib/selenium/webdriver/common/element.rb', line 48
def hash [@id, @bridge].hash end
#inspect
[ GitHub ]# File 'rb/lib/selenium/webdriver/common/element.rb', line 39
def inspect format '#<%<class>s:0x%<hash>x id=%<id>s>', class: self.class, hash: hash * 2, id: @id.inspect end
#location ⇒ WebDriver::Point
Get the location of this element.
# File 'rb/lib/selenium/webdriver/common/element.rb', line 286
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.
# File 'rb/lib/selenium/webdriver/common/element.rb', line 306
def location_once_scrolled_into_view bridge.element_location_once_scrolled_into_view @id end
#property(name) ⇒ String
?
Gets the value of a JavaScript property of this element This will return the current value, even if this has been modified after the page has been loaded. If the value is not set, nil is returned.
# File 'rb/lib/selenium/webdriver/common/element.rb', line 159
def property(name) bridge.element_property @id, name end
#rect ⇒ WebDriver::Rectangle
Get the dimensions and coordinates of this element.
# File 'rb/lib/selenium/webdriver/common/element.rb', line 296
def rect bridge.element_rect @id end
#ref
# File 'rb/lib/selenium/webdriver/common/element.rb', line 354
def ref [:element, @id] end
#screenshot (private)
[ GitHub ]# File 'rb/lib/selenium/webdriver/common/element.rb', line 390
def screenshot bridge.element_screenshot(@id) end
#send_key(*args)
Alias for #send_keys.
# File 'rb/lib/selenium/webdriver/common/element.rb', line 210
alias send_key send_keys
#send_keys(*args) 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: ' '
#shadow_root ⇒ WebDriver::ShadowRoot
Returns the shadow root of an element.
# File 'rb/lib/selenium/webdriver/common/element.rb', line 326
def shadow_root bridge.shadow_root @id end
#size ⇒ WebDriver::Dimension
Get the size of this element
# File 'rb/lib/selenium/webdriver/common/element.rb', line 316
def size bridge.element_size @id end
#style(prop)
Alias for #css_value.
# File 'rb/lib/selenium/webdriver/common/element.rb', line 278
alias style css_value
#submit
Submit this element
# File 'rb/lib/selenium/webdriver/common/element.rb', line 260
def submit bridge.submit_element @id end
#tag_name ⇒ String
Get the tag name of the element.
# File 'rb/lib/selenium/webdriver/common/element.rb', line 90
def tag_name bridge.element_tag_name @id end
#text ⇒ String
Get the text content of this element
# File 'rb/lib/selenium/webdriver/common/element.rb', line 189
def text bridge.element_text @id end
#to_json
Convert to a WebElement JSON Object for transmission over the wire.
# File 'rb/lib/selenium/webdriver/common/element.rb', line 365
def to_json(*) JSON.generate as_json end