Class: FireWatir::Option

Inherits:
InputElement show all
Defined in:
lib/firewatir/elements/option.rb

Overview

Description:

Class for Option element.

Constant Summary

Constants inherited from Element

Element::FIRST_ORDERED_NODE_TYPE, Element::NUMBER_TYPE, Element::ORDERED_NODE_ITERATOR_TYPE, Element::TO_S_SIZE

Constants included from Container

Container::DEFAULT_HIGHLIGHT_COLOR, Container::MACHINE_IP

Instance Attribute Summary

Attributes inherited from InputElement

#element_name

Attributes inherited from Element

#element_name

Instance Method Summary collapse

Methods inherited from InputElement

#locate

Methods inherited from Element

#assert_enabled, #attribute_value, #click, #contains_text, #disabled, #document_var, #element_by_xpath, #element_type, #elements_by_xpath, #enabled?, #exists?, #fire_event, #inspect, #method_missing, #to_s, #visible?, #wait

Methods included from Container

#button, #cell, #checkbox, #dd, #dl, #dt, #file_field, #form, #frame, #hidden, #image, #link, #radio, #row, #select_list, #show_all_objects, #table, #text_field

Methods included from JsshSocket

#js_eval, #js_eval_method, #jssh_socket, #read_socket

Constructor Details

#initialize(select_list, attribute, value) ⇒ Option

Description:

Initializes the instance of option object.

Input:

- select_list - instance of select list element.
- attribute - Attribute to identify the option.
- value - Value of that attribute.


16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/firewatir/elements/option.rb', line 16

def initialize (select_list, attribute, value)
  @select_list = @container = select_list
  @how = attribute
  @what = value
  @option = nil
  @element_name = ""
  
  unless [:text, :value, :jssh_name].include? attribute 
    raise MissingWayOfFindingObjectException,
            "Option does not support attribute #{@how}"
  end
  #puts @select_list.o.length
  #puts "what is : #{@what}, how is #{@how}, list name is : #{@select_list.element_name}"
  if(attribute == :jssh_name)
    @element_name = @what
    @option = self
  else    
    @select_list.o.each do |option| # items in the list
      #puts "option is : #{option}"
      if(attribute == :value)
        match_value = option.value
      else    
        match_value = option.text
      end    
      #puts "value is #{match_value}"
      if value.matches( match_value) #option.invoke(attribute))
        @option = option
        @element_name = option.element_name
        break
      end
    end
  end    
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class FireWatir::Element

Instance Method Details

#class_nameObject

Description:

Gets the class name of the option.

Output:

Class name of the option.


82
83
84
85
86
# File 'lib/firewatir/elements/option.rb', line 82

def class_name
  assert_exists
  jssh_socket.send("#{element_object}.className;\n", 0)
  return read_socket()
end

#selectObject

Description:

Selects the option.


66
67
68
69
70
71
72
73
# File 'lib/firewatir/elements/option.rb', line 66

def select
  assert_exists
  if(@how == :text)
    @select_list.select(@what)
  elsif(@how == :value)
    @select_list.select_value(@what)
  end    
end

#selectedObject

Description:

Gets the status of the option; whether it is selected or not.

Output:

True if option is selected, false otherwise.


121
122
123
124
125
126
127
# File 'lib/firewatir/elements/option.rb', line 121

def selected
  assert_exists
  jssh_socket.send("#{element_object}.selected;\n", 0)
  value = read_socket()
  return true if value == "true"
  return false if value == "false"
end

#textObject

Description:

Gets the text of the option.

Output:

Text of the option.


95
96
97
98
99
# File 'lib/firewatir/elements/option.rb', line 95

def text
  assert_exists
  jssh_socket.send("#{element_object}.text;\n", 0)
  return read_socket()
end

#valueObject

Description:

Gets the value of the option.

Output:

Value of the option.


108
109
110
111
112
# File 'lib/firewatir/elements/option.rb', line 108

def value
  assert_exists
  jssh_socket.send("#{element_object}.value;\n", 0)
  return read_socket()
end