Class: Selenium::WebDriver::Element
- Inherits:
-
Object
- Object
- Selenium::WebDriver::Element
- Includes:
- Find
- Defined in:
- lib/selenium/webdriver/element.rb
Constant Summary
Constants included from Find
Instance Attribute Summary collapse
-
#bridge ⇒ Object
readonly
Returns the value of attribute bridge.
Instance Method Summary collapse
- #==(other) ⇒ Object (also: #eql?)
-
#attribute(name) ⇒ String?
(also: #[])
Get the value of the given attribute.
-
#clear ⇒ Object
Clear this element.
-
#click ⇒ Object
Click the element.
-
#displayed? ⇒ Boolean
Is the element displayed?.
-
#drag_and_drop_by(right_by, down_by) ⇒ Object
Drag and drop this element.
-
#drag_and_drop_on(other) ⇒ Object
Drag and drop this element on the given element.
-
#enabled? ⇒ Boolean
Is the element enabled?.
- #hash ⇒ Object
-
#hover ⇒ Object
Hover over this element.
-
#initialize(bridge, id) ⇒ Element
constructor
Creates a new Element.
- #inspect ⇒ Object
-
#location ⇒ WebDriver::Point
Get the location of this element.
-
#ref ⇒ Object
for Find and execute_script.
-
#select ⇒ Object
Select this element.
-
#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
Convert to a WebElement JSON Object for transmission over the wire.
-
#toggle ⇒ Object
Toggle this element.
-
#value ⇒ String
Get the value of this element.
Methods included from Find
Constructor Details
#initialize(bridge, id) ⇒ Element
Creates a new Element
14 15 16 |
# File 'lib/selenium/webdriver/element.rb', line 14 def initialize(bridge, id) @bridge, @id = bridge, id end |
Instance Attribute Details
#bridge ⇒ Object (readonly)
Returns the value of attribute bridge.
6 7 8 |
# File 'lib/selenium/webdriver/element.rb', line 6 def bridge @bridge end |
Instance Method Details
#==(other) ⇒ Object Also known as: eql?
22 23 24 |
# File 'lib/selenium/webdriver/element.rb', line 22 def ==(other) other.kind_of?(self.class) && bridge.elementEquals(self, other) end |
#attribute(name) ⇒ String? Also known as: []
Get the value of the given attribute
68 69 70 |
# File 'lib/selenium/webdriver/element.rb', line 68 def attribute(name) bridge.getElementAttribute @id, name end |
#clear ⇒ Object
Clear this element
115 116 117 |
# File 'lib/selenium/webdriver/element.rb', line 115 def clear bridge.clearElement @id end |
#click ⇒ Object
Click the element
35 36 37 |
# File 'lib/selenium/webdriver/element.rb', line 35 def click bridge.clickElement @id end |
#displayed? ⇒ Boolean
Is the element displayed?
145 146 147 |
# File 'lib/selenium/webdriver/element.rb', line 145 def displayed? bridge.isElementDisplayed @id end |
#drag_and_drop_by(right_by, down_by) ⇒ Object
Drag and drop this element
218 219 220 |
# File 'lib/selenium/webdriver/element.rb', line 218 def drag_and_drop_by(right_by, down_by) bridge.dragElement @id, right_by, down_by end |
#drag_and_drop_on(other) ⇒ Object
Drag and drop this element on the given element
228 229 230 231 232 233 234 235 236 |
# File 'lib/selenium/webdriver/element.rb', line 228 def drag_and_drop_on(other) current_location = location() destination = other.location right = destination.x - current_location.x down = destination.y - current_location.y drag_and_drop_by right, down end |
#enabled? ⇒ Boolean
Is the element enabled?
125 126 127 |
# File 'lib/selenium/webdriver/element.rb', line 125 def enabled? bridge.isElementEnabled @id end |
#hash ⇒ Object
27 28 29 |
# File 'lib/selenium/webdriver/element.rb', line 27 def hash ref.hash end |
#hover ⇒ Object
Hover over this element. Not applicable to all browsers.
185 186 187 |
# File 'lib/selenium/webdriver/element.rb', line 185 def hover bridge.hoverOverElement @id end |
#inspect ⇒ Object
18 19 20 |
# File 'lib/selenium/webdriver/element.rb', line 18 def inspect '#<%s:0x%x id=%s tag_name=%s>' % [self.class, hash*2, @id.inspect, tag_name.inspect] end |
#location ⇒ WebDriver::Point
Get the location of this element.
195 196 197 |
# File 'lib/selenium/webdriver/element.rb', line 195 def location bridge.getElementLocation @id end |
#ref ⇒ Object
for Find and execute_script
263 264 265 |
# File 'lib/selenium/webdriver/element.rb', line 263 def ref @id end |
#select ⇒ Object
Select this element
153 154 155 |
# File 'lib/selenium/webdriver/element.rb', line 153 def select bridge.setElementSelected @id end |
#selected? ⇒ Boolean
Is the element selected?
135 136 137 |
# File 'lib/selenium/webdriver/element.rb', line 135 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: ' '
96 97 98 99 100 101 102 103 104 105 106 107 108 |
# File 'lib/selenium/webdriver/element.rb', line 96 def send_keys(*args) args.each do |arg| case arg when Symbol arg = Keys[arg] when Array arg = arg.map { |e| e.kind_of?(Symbol) ? Keys[e] : e }.join arg << Keys[:null] end bridge.sendKeysToElement(@id, arg.to_s) end end |
#size ⇒ WebDriver::Dimension
Get the size of this element
205 206 207 |
# File 'lib/selenium/webdriver/element.rb', line 205 def size bridge.getElementSize @id end |
#style(prop) ⇒ Object
Get the value of the given CSS property
177 178 179 |
# File 'lib/selenium/webdriver/element.rb', line 177 def style(prop) bridge.getElementValueOfCssProperty @id, prop end |
#submit ⇒ Object
Submit this element
161 162 163 |
# File 'lib/selenium/webdriver/element.rb', line 161 def submit bridge.submitElement @id end |
#tag_name ⇒ String
Get the tag name of this element
45 46 47 |
# File 'lib/selenium/webdriver/element.rb', line 45 def tag_name bridge.getElementTagName @id end |
#text ⇒ String
Get the text content of this element
78 79 80 |
# File 'lib/selenium/webdriver/element.rb', line 78 def text bridge.getElementText @id end |
#to_json(*args) ⇒ Object
Convert to a WebElement JSON Object for transmission over the wire.
274 275 276 |
# File 'lib/selenium/webdriver/element.rb', line 274 def to_json(*args) { :ELEMENT => @id }.to_json(*args) end |
#toggle ⇒ Object
Toggle this element
169 170 171 |
# File 'lib/selenium/webdriver/element.rb', line 169 def toggle bridge.toggleElement @id end |
#value ⇒ String
Get the value of this element
55 56 57 |
# File 'lib/selenium/webdriver/element.rb', line 55 def value bridge.getElementValue @id end |