Class: Selenium::WebDriver::Element

Inherits:
Object
  • Object
show all
Includes:
Find
Defined in:
lib/selenium/webdriver/element.rb

Constant Summary

Constants included from Find

Find::FINDERS

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Find

#find_element, #find_elements

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

#bridgeObject (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

#attribute(name) ⇒ String? Also known as: []

Get the value of the given attribute

Parameters:

Returns:

  • (String, nil)

    attribute value



59
60
61
# File 'lib/selenium/webdriver/element.rb', line 59

def attribute(name)
  bridge.getElementAttribute @id, name
end

#clearObject

Clear this element



106
107
108
# File 'lib/selenium/webdriver/element.rb', line 106

def clear
  bridge.clearElement @id
end

#clickObject

Click the element



26
27
28
# File 'lib/selenium/webdriver/element.rb', line 26

def click
  bridge.clickElement @id
end

#displayed?Boolean

Is the element displayed?

Returns:

  • (Boolean)


136
137
138
# File 'lib/selenium/webdriver/element.rb', line 136

def displayed?
  bridge.isElementDisplayed @id
end

#drag_and_drop_by(right_by, down_by) ⇒ Object

Drag and drop this element

Parameters:

  • right_by (Integer)

    number of pixels to drag right

  • down_by (Integer)

    number of pixels to drag down



209
210
211
# File 'lib/selenium/webdriver/element.rb', line 209

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

Parameters:



219
220
221
222
223
224
225
226
227
# File 'lib/selenium/webdriver/element.rb', line 219

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?

Returns:

  • (Boolean)


116
117
118
# File 'lib/selenium/webdriver/element.rb', line 116

def enabled?
  bridge.isElementEnabled @id
end

#hoverObject

Hover over this element. Not applicable to all browsers.



176
177
178
# File 'lib/selenium/webdriver/element.rb', line 176

def hover
  bridge.hoverOverElement @id
end

#inspectObject



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

#locationWebDriver::Point

Get the location of this element.

Returns:



186
187
188
# File 'lib/selenium/webdriver/element.rb', line 186

def location
  bridge.getElementLocation @id
end

#refObject

for Find and execute_script



254
255
256
# File 'lib/selenium/webdriver/element.rb', line 254

def ref
  @id
end

#selectObject

Select this element



144
145
146
# File 'lib/selenium/webdriver/element.rb', line 144

def select
  bridge.setElementSelected @id
end

#selected?Boolean

Is the element selected?

Returns:

  • (Boolean)


126
127
128
# File 'lib/selenium/webdriver/element.rb', line 126

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: ' '

Parameters:

See Also:



87
88
89
90
91
92
93
94
95
96
97
98
99
# File 'lib/selenium/webdriver/element.rb', line 87

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

#sizeWebDriver::Dimension

Get the size of this element



196
197
198
# File 'lib/selenium/webdriver/element.rb', line 196

def size
  bridge.getElementSize @id
end

#style(prop) ⇒ Object

Get the value of the given CSS property



168
169
170
# File 'lib/selenium/webdriver/element.rb', line 168

def style(prop)
  bridge.getElementValueOfCssProperty @id, prop
end

#submitObject

Submit this element



152
153
154
# File 'lib/selenium/webdriver/element.rb', line 152

def submit
  bridge.submitElement @id
end

#tag_nameString

Get the tag name of this element

Returns:



36
37
38
# File 'lib/selenium/webdriver/element.rb', line 36

def tag_name
  bridge.getElementTagName @id
end

#textString

Get the text content of this element

Returns:



69
70
71
# File 'lib/selenium/webdriver/element.rb', line 69

def text
  bridge.getElementText @id
end

#to_json(*args) ⇒ Object

Convert to a WebElement JSON Object for transmission over the wire.



265
266
267
# File 'lib/selenium/webdriver/element.rb', line 265

def to_json(*args)
  { :ELEMENT => @id }.to_json(*args)
end

#toggleObject

Toggle this element



160
161
162
# File 'lib/selenium/webdriver/element.rb', line 160

def toggle
  bridge.toggleElement @id
end

#valueString

Get the value of this element

Returns:



46
47
48
# File 'lib/selenium/webdriver/element.rb', line 46

def value
  bridge.getElementValue @id
end