Module: WatirRobot::Element

Included in:
KeywordLibrary
Defined in:
lib/watir_robot/keywords/element.rb

Overview

Functionality related to HTML elements in a generic, global context

Instance Method Summary collapse

Instance Method Details

#click_element(loc) ⇒ Object

Click any HTML element

Parameters:

  • loc (String)

    attribute/value pairs that match an HTML element



36
37
38
# File 'lib/watir_robot/keywords/element.rb', line 36

def click_element(loc)
  @browser.element(parse_location(loc)).click
end

#element_should_be_visible(loc) ⇒ Object

Verify that an element is visible

Parameters:

  • loc (String)

    attribute/value pairs that match an HTML element

Raises:



76
77
78
79
# File 'lib/watir_robot/keywords/element.rb', line 76

def element_should_be_visible(loc)
  raise(Exception::ElementVisibilityError, "The element described by #{parse_location(loc)} is not visible.") unless
    @browser.element(parse_location(loc)).visible?
end

#element_should_not_be_visible(loc) ⇒ Object

Verify that an element is not visible

Parameters:

  • loc (String)

    attribute/value pairs that match an HTML element

Raises:



86
87
88
89
# File 'lib/watir_robot/keywords/element.rb', line 86

def element_should_not_be_visible(loc)
  raise(Exception::ElementVisibilityError, "The element described by #{parse_location(loc)} is visible erroneously.") if
    @browser.element(parse_location(loc)).visible?
end

#element_text_should_be(loc, text) ⇒ Object

Verify that an element’s text matches a specific value

Parameters:

  • loc (String)

    attribute/value pairs that match an HTML element

  • text (String)

    the text to compare against

Raises:



107
108
109
110
# File 'lib/watir_robot/keywords/element.rb', line 107

def element_text_should_be(loc, text)
  raise(Exception::ElementMatchError, "The element's text #{@browser.element(parse_location(loc)).text} does not equal #{text}.") unless
    @browser.element(parse_location(loc)).text == text      
end

#element_text_should_contain(loc, text) ⇒ Object

Verify that an element’s text contains a specific value

Parameters:

  • loc (String)

    attribute/value pairs that match an HTML element

  • text (String)

    the text to compare against

Raises:



97
98
99
100
# File 'lib/watir_robot/keywords/element.rb', line 97

def element_text_should_contain(loc, text)
  raise(Exception::ElementMatchError, "The element's text #{@browser.element(parse_location(loc)).text} does not contain the text #{text}.") unless
    @browser.element(parse_location(loc)).text.include? text
end

#focus(loc) ⇒ Object

Set focus to element

Parameters:

  • loc (String)

    attribute/value pairs that match an HTML element



45
46
47
# File 'lib/watir_robot/keywords/element.rb', line 45

def focus(loc)
  @browser.element(parse_location(loc)).focus
end

#get_element_attribute(loc, attr) ⇒ String

Get the value of an attribute for an element

Parameters:

  • loc (String)

    attribute/value pairs that match an HTML element

  • attr (String)

    the attribute for which to return a value

Returns:

  • (String)

    the value of the attribute for the given HTML element



17
18
19
# File 'lib/watir_robot/keywords/element.rb', line 17

def get_element_attribute(loc, attr)
  @browser.element(parse_location(loc)).attribute_value(attr)
end

#get_element_text(loc) ⇒ String

Get an element’s text

Parameters:

  • loc (String)

    attribute/value pairs that match an HTML element

Returns:

  • (String)

    the text of a given HTML without any HTML markup



27
28
29
# File 'lib/watir_robot/keywords/element.rb', line 27

def get_element_text(loc)
  @browser.element(parse_location(loc)).text
end

#send_keys(loc, text) ⇒ Object

Type text into the given text field (alternate for “Type Text”)

Parameters:

  • loc (String)

    attribute/value pairs that match an HTML element

  • text (String)

    the text to type into the field



55
56
57
# File 'lib/watir_robot/keywords/element.rb', line 55

def send_keys(loc, text)
  @browser.element(parse_location(loc)).send_keys(text)
end

#type_text(loc, text) ⇒ Object

Type text into the given text field (alternate for “Send Keys”)

Parameters:

  • loc (String)

    attribute/value pairs that match an HTML element

  • text (String)

    the text to type into the field



65
66
67
# File 'lib/watir_robot/keywords/element.rb', line 65

def type_text(loc, text)
  @browser.element(parse_location(loc)).send_keys(text)
end