class Selenium::WebDriver::Element

Public Class Methods

new(bridge, id) click to toggle source

Creates a new Element

@api private

# File lib/selenium/webdriver/common/element.rb, line 12
def initialize(bridge, id)
  @bridge, @id = bridge, id
end

Public Instance Methods

==(other) click to toggle source
# File lib/selenium/webdriver/common/element.rb, line 20
def ==(other)
  other.kind_of?(self.class) && bridge.elementEquals(self, other)
end
Also aliased as: eql?
[](name)

element or element #=> “someclass”

Alias for: attribute
as_json(opts = nil) click to toggle source

For Rails 3 - jonathanjulian.com/2010/04/rails-to_json-or-as_json/

@api private

# File lib/selenium/webdriver/common/element.rb, line 250
def as_json(opts = nil)
  { :ELEMENT => @id }
end
attribute(name) click to toggle source

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

@param [String]

attribute name

@return [String,nil]

attribute value
# File lib/selenium/webdriver/common/element.rb, line 73
def attribute(name)
  bridge.getElementAttribute @id, name
end
Also aliased as: []
clear() click to toggle source

Clear this element

# File lib/selenium/webdriver/common/element.rb, line 124
def clear
  bridge.clearElement @id
end
click() click to toggle source

Click the element

# File lib/selenium/webdriver/common/element.rb, line 33
def click
  bridge.clickElement @id
end
displayed?() click to toggle source

Is the element displayed?

@return [Boolean]

# File lib/selenium/webdriver/common/element.rb, line 154
def displayed?
  bridge.isElementDisplayed @id
end
enabled?() click to toggle source

Is the element enabled?

@return [Boolean]

# File lib/selenium/webdriver/common/element.rb, line 134
def enabled?
  bridge.isElementEnabled @id
end
eql?(other)
Alias for: ==
hash() click to toggle source
# File lib/selenium/webdriver/common/element.rb, line 25
def hash
  @id.hash ^ @bridge.hash
end
inspect() click to toggle source
# File lib/selenium/webdriver/common/element.rb, line 16
def inspect
  '#<%s:0x%x id=%s>' % [self.class, hash*2, @id.inspect]
end
location() click to toggle source

Get the location of this element.

@return [WebDriver::Point]

# File lib/selenium/webdriver/common/element.rb, line 180
def location
  bridge.getElementLocation @id
end
location_once_scrolled_into_view() click to toggle source

Determine an element's location on the screen once it has been scrolled into view.

@return [WebDriver::Point]

# File lib/selenium/webdriver/common/element.rb, line 190
def location_once_scrolled_into_view
  bridge.getElementLocationOnceScrolledIntoView @id
end
ref() click to toggle source

for SearchContext and execute_script

@api private

# File lib/selenium/webdriver/common/element.rb, line 229
def ref
  @id
end
selected?() click to toggle source

Is the element selected?

@return [Boolean]

# File lib/selenium/webdriver/common/element.rb, line 144
def selected?
  bridge.isElementSelected @id
end
send_key(*args)
Alias for: send_keys
send_keys(*args) click to toggle source

Send keystrokes to this element

@param [String, Symbol, Array]

Examples:

element.send_keys "foo"                     #=> value: 'foo'
element.send_keys "tet", :arrow_left, "s"   #=> value: 'test'
element.send_keys [:control, 'a'], :space   #=> value: ' '

@see Keys::KEYS

# File lib/selenium/webdriver/common/element.rb, line 101
def send_keys(*args)
  values = args.map do |arg|
    case arg
    when Symbol
      Keys[arg]
    when Array
      arg = arg.map { |e| e.kind_of?(Symbol) ? Keys[e] : e }.join
      arg << Keys[:null]

      arg
    else
      arg.to_s
    end
  end

  bridge.sendKeysToElement @id, values
end
Also aliased as: send_key
size() click to toggle source

Get the size of this element

@return [WebDriver::Dimension]

# File lib/selenium/webdriver/common/element.rb, line 200
def size
  bridge.getElementSize @id
end
style(prop) click to toggle source

Get the value of the given CSS property

# File lib/selenium/webdriver/common/element.rb, line 170
def style(prop)
  bridge.getElementValueOfCssProperty @id, prop
end
submit() click to toggle source

Submit this element

# File lib/selenium/webdriver/common/element.rb, line 162
def submit
  bridge.submitElement @id
end
tag_name() click to toggle source

Get the tag name of this element

@return [String]

# File lib/selenium/webdriver/common/element.rb, line 43
def tag_name
  bridge.getElementTagName @id
end
text() click to toggle source

Get the text content of this element

@return [String]

# File lib/selenium/webdriver/common/element.rb, line 83
def text
  bridge.getElementText @id
end
to_json(*args) click to toggle source

Convert to a WebElement JSON Object for transmission over the wire. @see code.google.com/p/selenium/wiki/JsonWireProtocol#Basic_Concepts_And_Terms

@api private

# File lib/selenium/webdriver/common/element.rb, line 240
def to_json(*args)
  as_json.to_json(*args)
end

Private Instance Methods

bridge() click to toggle source
# File lib/selenium/webdriver/common/element.rb, line 256
def bridge
  @bridge
end
selectable?() click to toggle source
# File lib/selenium/webdriver/common/element.rb, line 260
def selectable?
  tn = tag_name.downcase
  type = attribute(:type).to_s.downcase

  tn == "option" || (tn == "input" && %w[radio checkbox].include?(type))
end