### Home Classes Methods

### In Files

- lib/selenium/webdriver/common/element.rb

### Parent

Object

### Methods

- ::new
- #==
- #[]
- #as_json
- #attribute
- #clear
- #click
- #css_value
- #displayed?
- #enabled?
- #eql?
- #hash
- #inspect
- #location
- #location_once_scrolled_into_view
- #ref
- #selected?
- #send_key
- #send_keys
- #size
- #style
- #submit
- #tag_name
- #text
- #to_json

### Included Modules

- Selenium::WebDriver::SearchContext

### Class/Module Index

Quicksearch

- Selenium
- Selenium::Client
- Selenium::Client::Base
- Selenium::Client::CommandError
- Selenium::Client::Driver
- Selenium::Client::Extensions
- Selenium::Client::GeneratedDriver
- Selenium::Client::Idiomatic
- Selenium::Client::JavascriptExpressionBuilder
- Selenium::Client::JavascriptFrameworks
- Selenium::Client::JavascriptFrameworks::JQuery
- Selenium::Client::JavascriptFrameworks::Prototype
- Selenium::Client::Protocol
- Selenium::Client::ProtocolError
- Selenium::Client::SeleniumHelper
- Selenium::Rake
- Selenium::Rake::MissingJarFileError
- Selenium::Rake::ServerTask
- Selenium::Server
- Selenium::Server::Error
- Selenium::WebDriver
- Selenium::WebDriver::ActionBuilder
- Selenium::WebDriver::Alert
- Selenium::WebDriver::Android
- Selenium::WebDriver::Android::Bridge
- Selenium::WebDriver::BridgeHelper
- Selenium::WebDriver::Chrome
- Selenium::WebDriver::Chrome::Bridge
- Selenium::WebDriver::Chrome::Profile
- Selenium::WebDriver::Chrome::Service
- Selenium::WebDriver::Driver
- Selenium::WebDriver::DriverExtensions
- Selenium::WebDriver::DriverExtensions::HasBrowserConnection
- Selenium::WebDriver::DriverExtensions::HasInputDevices
- Selenium::WebDriver::DriverExtensions::HasLocation
- Selenium::WebDriver::DriverExtensions::HasSessionId
- Selenium::WebDriver::DriverExtensions::HasTouchScreen
- Selenium::WebDriver::DriverExtensions::HasWebStorage
- Selenium::WebDriver::DriverExtensions::Rotatable
- Selenium::WebDriver::DriverExtensions::TakesScreenshot
- Selenium::WebDriver::DriverExtensions::UploadsFiles
- Selenium::WebDriver::Element
- Selenium::WebDriver::Error
- Selenium::WebDriver::Error::ElementNotDisplayedError
- Selenium::WebDriver::Error::ElementNotSelectableError
- Selenium::WebDriver::Error::ElementNotVisibleError
- Selenium::WebDriver::Error::ExpectedError
- Selenium::WebDriver::Error::IMEEngineActivationFailedError
- Selenium::WebDriver::Error::IMENotAvailableError
- Selenium::WebDriver::Error::IndexOutOfBoundsError
- Selenium::WebDriver::Error::InvalidCookieDomainError
- Selenium::WebDriver::Error::InvalidElementCoordinatesError
- Selenium::WebDriver::Error::InvalidElementStateError
- Selenium::WebDriver::Error::InvalidSelectorError
- Selenium::WebDriver::Error::JavascriptError
- Selenium::WebDriver::Error::MoveTargetOutOfBoundsError
- Selenium::WebDriver::Error::NoAlertOpenError
- Selenium::WebDriver::Error::NoAlertPresentError
- Selenium::WebDriver::Error::NoCollectionError
- Selenium::WebDriver::Error::NoScriptResultError
- Selenium::WebDriver::Error::NoStringError
- Selenium::WebDriver::Error::NoStringLengthError
- Selenium::WebDriver::Error::NoStringWrapperError
- Selenium::WebDriver::Error::NoSuchCollectionError
- Selenium::WebDriver::Error::NoSuchDocumentError
- Selenium::WebDriver::Error::NoSuchDriverError
- Selenium::WebDriver::Error::NoSuchElementError
- Selenium::WebDriver::Error::NoSuchFrameError
- Selenium::WebDriver::Error::NoSuchWindowError
- Selenium::WebDriver::Error::NullPointerError
- Selenium::WebDriver::Error::ObsoleteElementError
- Selenium::WebDriver::Error::ScriptTimeOutError
- Selenium::WebDriver::Error::ServerError
- Selenium::WebDriver::Error::StaleElementReferenceError
- Selenium::WebDriver::Error::TimeOutError
- Selenium::WebDriver::Error::UnableToSetCookieError
- Selenium::WebDriver::Error::UnexpectedJavascriptError
- Selenium::WebDriver::Error::UnhandledAlertError
- Selenium::WebDriver::Error::UnhandledError
- Selenium::WebDriver::Error::UnknownCommandError
- Selenium::WebDriver::Error::UnknownError
- Selenium::WebDriver::Error::UnsupportedOperationError
- Selenium::WebDriver::Error::WebDriverError
- Selenium::WebDriver::Error::XPathLookupError
- Selenium::WebDriver::FileReaper
- Selenium::WebDriver::Firefox
- Selenium::WebDriver::Firefox::Binary
- Selenium::WebDriver::Firefox::Bridge
- Selenium::WebDriver::Firefox::Extension
- Selenium::WebDriver::Firefox::Launcher
- Selenium::WebDriver::Firefox::Profile
- Selenium::WebDriver::Firefox::ProfilesIni
- Selenium::WebDriver::Firefox::SocketLock
- Selenium::WebDriver::Firefox::Util
- Selenium::WebDriver::HTML5
- Selenium::WebDriver::HTML5::LocalStorage
- Selenium::WebDriver::HTML5::SessionStorage
- Selenium::WebDriver::HTML5::SharedWebStorage
- Selenium::WebDriver::IE
- Selenium::WebDriver::IE::Bridge
- Selenium::WebDriver::IE::Server
- Selenium::WebDriver::IPhone
- Selenium::WebDriver::IPhone::Bridge
- Selenium::WebDriver::JsonHelper
- Selenium::WebDriver::Keyboard
- Selenium::WebDriver::Keys
- Selenium::WebDriver::LogEntry
- Selenium::WebDriver::Mouse
- Selenium::WebDriver::Navigation
- Selenium::WebDriver::Opera
- Selenium::WebDriver::Opera::Bridge
- Selenium::WebDriver::Opera::Service
- Selenium::WebDriver::Options
- Selenium::WebDriver::PhantomJS
- Selenium::WebDriver::PhantomJS::Bridge
- Selenium::WebDriver::PhantomJS::Service
- Selenium::WebDriver::Platform
- Selenium::WebDriver::PortProber
- Selenium::WebDriver::ProfileHelper
- Selenium::WebDriver::ProfileHelper::ClassMethods
- Selenium::WebDriver::Proxy
- Selenium::WebDriver::Remote
- Selenium::WebDriver::Remote::Bridge
- Selenium::WebDriver::Remote::Capabilities
- Selenium::WebDriver::Remote::Http
- Selenium::WebDriver::Remote::Http::Common
- Selenium::WebDriver::Remote::Http::Curb
- Selenium::WebDriver::Remote::Http::Default
- Selenium::WebDriver::Remote::Http::Persistent
- Selenium::WebDriver::Remote::Response
- Selenium::WebDriver::Safari
- Selenium::WebDriver::Safari::Bridge
- Selenium::WebDriver::Safari::Browser
- Selenium::WebDriver::Safari::Extension
- Selenium::WebDriver::Safari::Server
- Selenium::WebDriver::SearchContext
- Selenium::WebDriver::SocketPoller
- Selenium::WebDriver::Support
- Selenium::WebDriver::Support::AbstractEventListener
- Selenium::WebDriver::Support::BlockEventListener
- Selenium::WebDriver::Support::Color
- Selenium::WebDriver::Support::EventFiringBridge
- Selenium::WebDriver::Support::Select
- Selenium::WebDriver::Support::Select::Escaper
- Selenium::WebDriver::TargetLocator
- Selenium::WebDriver::Timeouts
- Selenium::WebDriver::TouchActionBuilder
- Selenium::WebDriver::TouchScreen
- Selenium::WebDriver::Wait
- Selenium::WebDriver::Window
- Selenium::WebDriver::Zipper
- Base64
- Dir
- SocketError
- String

No matching classes.

# 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) click to toggle source

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 274
    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 97
    def attribute(name)
      bridge.getElementAttribute @id, name
    end

Also aliased as: []
clear() click to toggle source

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 lib/selenium/webdriver/common/element.rb, line 140
    def clear
      bridge.clearElement @id
    end

click() click to toggle source

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)

@example Click on a button

    driver.find_element(:tag_name, "button").click

@raise [StaleElementReferenceError] if the element no longer exists as

    defined

    # File lib/selenium/webdriver/common/element.rb, line 53
    def click
      bridge.clickElement @id
    end

css_value(prop) click to toggle source

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.

@see www.w3.org/TR/DOM-Level-2-Style/css.html#CSS-CSSStyleDeclaration

    # File lib/selenium/webdriver/common/element.rb, line 193
    def css_value(prop)
      bridge.getElementValueOfCssProperty @id, prop
    end

Also aliased as: style
displayed?() click to toggle source

Is the element displayed?

@return [Boolean]

    # File lib/selenium/webdriver/common/element.rb, line 170
    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 150
    def enabled?
      bridge.isElementEnabled @id
    end

eql?(other) click to toggle source
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 204
    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 214
    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 253
    def ref
      @id
    end

selected?() click to toggle source

Is the element selected?

@return [Boolean]

    # File lib/selenium/webdriver/common/element.rb, line 160
    def selected?
      bridge.isElementSelected @id
    end

send_key(*args) click to toggle source
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 125
    def send_keys(*args)
      bridge.sendKeysToElement @id, Keys.encode(args)
    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 224
    def size
      bridge.getElementSize @id
    end

style(prop) click to toggle source
Alias for: css_value
submit() click to toggle source

Submit this element

    # File lib/selenium/webdriver/common/element.rb, line 178
    def submit
      bridge.submitElement @id
    end

tag_name() click to toggle source

Get the tag name of the element.

@example Get the tagname of an INPUT element(returns "input")

    driver.find_element(:xpath, "//input").tag_name

@return [String] The tag name of this element.

    # File lib/selenium/webdriver/common/element.rb, line 67
    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 107
    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 264
    def to_json(*args)
      WebDriver.json_dump as_json
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.