Module: WatirRobot::TextField

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

Overview

Functionality related to text fields (+<input>+ of type text and password)

Instance Method Summary collapse

Instance Method Details

#append_to_textfield(loc, text) ⇒ Object

Append text to a given text field’s current value

Parameters:

  • loc (String)

    attribute/value pairs that match an HTML element



64
65
66
# File 'lib/watir_robot/keywords/text_field.rb', line 64

def append_to_textfield(loc, text)
  @browser.text_field(parse_location(loc)).append(text)
end

#clear_textfield(loc) ⇒ Object

Clear the given textfield

Parameters:

  • loc (String)

    attribute/value pairs that match an HTML element



47
48
49
# File 'lib/watir_robot/keywords/text_field.rb', line 47

def clear_textfield(loc)
  @browser.text_field(parse_location(loc)).clear
end

#focus_textfield(loc) ⇒ Object

Focus cursor inside a textfield

Parameters:

  • loc (String)

    attribute/value pairs that match an HTML element



15
16
17
# File 'lib/watir_robot/keywords/text_field.rb', line 15

def focus_textfield(loc)
  @browser.text_field(parse_location(loc)).focus
end

#get_textfield_value(loc) ⇒ Object

Get value of given text field

Parameters:

  • loc (String)

    attribute/value pairs that match an HTML element



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

def get_textfield_value(loc)
  @browser.text_field(parse_location(loc)).value
end

#input_password(loc, password) ⇒ Object

Note:

This value will not be logged.

Input a password into a password field.

Parameters:

  • loc (String)

    attribute/value pairs that match an HTML element

  • password (String)

    the password to type into the field



37
38
39
40
# File 'lib/watir_robot/keywords/text_field.rb', line 37

def input_password(loc, password)
  # This will differ from input_text when logging is implemented
  @browser.text_field(parse_location(loc)).set password
end

#input_text(loc, text) ⇒ Object

Input text into a text field

Parameters:

  • loc (String)

    attribute/value pairs that match an HTML element

  • text (String)

    the text to type into the field



25
26
27
# File 'lib/watir_robot/keywords/text_field.rb', line 25

def input_text(loc, text)
  @browser.text_field(parse_location(loc)).set text
end

#textfield_should_be(loc, text) ⇒ Object

Verify that textfield’s text is the value

Parameters:

  • loc (String)

    attribute/value pairs that match an HTML element

  • text (String)

    the text to compare against

Raises:



87
88
89
90
# File 'lib/watir_robot/keywords/text_field.rb', line 87

def textfield_should_be(loc, text)
  raise(Exception::ElementMatchError, "The textfield located at #{loc} does not have text equal to #{text}") unless
    @browser.text_field(parse_location(loc)).value == text
end

#textfield_should_contain(loc, text) ⇒ Object

Verify that textfield’s text contains the value

Parameters:

  • loc (String)

    attribute/value pairs that match an HTML element

  • text (String)

    the text to type into the field

Raises:



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

def textfield_should_contain(loc, text)
  raise(Exception::ElementMatchError, "The textfield located at #{loc} does not contain the text #{text}") unless
    @browser.text_field(parse_location(loc)).value.include? text
end