Class: Selenium::WebDriver::Element

Inherits:
Object
  • Object
show all
Includes:
SeleniumPlus::Elements::Select, SeleniumPlus::Elements::Table, SeleniumPlus::Finders
Defined in:
lib/selenium_plus/selenium/element.rb

Overview

Public: Add extension method to Element class

Instance Method Summary collapse

Methods included from SeleniumPlus::Finders

#find, #find_all

Methods included from SeleniumPlus::Elements::Select

#first_selected_option, #multiple?, #select, #select_options, #select_raw, #select_values, #selected_options

Methods included from SeleniumPlus::Elements::Table

#hashes, #headers, #headers_text, #rows, #rows_text, #table_raw, #table_raw_text

Instance Method Details

#[](attribute) ⇒ String

Retrieve the given attribute

Examples:

element[:name]                HTML name attribute

Parameters:

  • attribute (Symbol)

    The attribute to retrieve

Returns:

  • (String)

    The value of the attribute



16
17
18
# File 'lib/selenium_plus/selenium/element.rb', line 16

def [](attribute)
  self.attribute(attribute.to_s)
end

#append(text) ⇒ Object

Append text into text field element

Examples:

element.append('hello world')

Parameters:

  • text (Symbol)

Returns:



60
61
62
# File 'lib/selenium_plus/selenium/element.rb', line 60

def append(text)
  self.set("#{self.text} #{text}")
end

#set(value) ⇒ Object

Set the value of the element to the given value.

Examples:

element.set('Hello')

Parameters:

  • value (String)

    The new value

Returns:



32
33
34
35
36
37
# File 'lib/selenium_plus/selenium/element.rb', line 32

def set(value)
  tag_name = self.tag_name
  if tag_name == 'textarea' or tag_name == 'input'
    self.send_keys(value.to_s)
  end
end

#type(text) ⇒ Object

Type text into text field element

Examples:

element.type('hello world')

Parameters:

  • text (Symbol)

Returns:



47
48
49
50
# File 'lib/selenium_plus/selenium/element.rb', line 47

def type(text)
  self.clear
  self.set(text)
end

#visible?Boolean

Returns:

  • (Boolean)


20
21
22
# File 'lib/selenium_plus/selenium/element.rb', line 20

def visible?
  self.displayed?
end