Class: Symbiont::WebObjects::SelectList

Inherits:
WebObject
  • Object
show all
Defined in:
lib/symbiont/web_objects/select_list.rb

Instance Attribute Summary

Attributes inherited from WebObject

#web_object

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from WebObject

#==, #attribute, #clear, #click, #disabled?, #double_click, #enabled?, #exists?, #fire_event, #flash, #focus, #hover, #html, #id, #inspect, #parent, provide_locator_for, #scroll_into_view, selector_mapping, #send_keys, #style, #tag_name, #text, #value, #visible?, #wait_until, #when_actionable, #when_not_actionable, #when_not_visible, #when_visible

Constructor Details

#initialize(web_object) ⇒ SelectList

Returns a new instance of SelectList.



5
6
7
# File 'lib/symbiont/web_objects/select_list.rb', line 5

def initialize(web_object)
  @web_object = web_object
end

Class Method Details

.usable_selectorsObject



9
10
11
# File 'lib/symbiont/web_objects/select_list.rb', line 9

def self.usable_selectors
  super + [:value, :text, :label]
end

Instance Method Details

#[](idx) ⇒ Symbiont::WebObjects::Option

This method is used to return an Option object based on the index provided.



15
16
17
# File 'lib/symbiont/web_objects/select_list.rb', line 15

def [](idx)
  ::Symbiont::WebObjects::Option.new(options[idx])
end

#include?(value) ⇒ Boolean

This method checks to see if the select list has one or more options where the text or the label matches the provided value.

Parameters:

  • value (String, Regexp)

    A value to check for.

Returns:

  • (Boolean)


67
68
69
# File 'lib/symbiont/web_objects/select_list.rb', line 67

def include?(value)
  web_object.include? value
end

#optionsarray of Symbiont::WebObjects::Option

This method returns an array of Option objects that are contained within a select list object.

Returns:



32
33
34
35
36
37
38
39
# File 'lib/symbiont/web_objects/select_list.rb', line 32

def options
  web_objects = []
  options = web_object.wd.find_elements(:xpath, option_xpath)
  options.each do |opt|
    web_objects << ::Symbiont::WebObjects::Option.new(opt)
  end
  web_objects
end

#select(value) ⇒ Object

Selects an option from the select list.



20
21
22
# File 'lib/symbiont/web_objects/select_list.rb', line 20

def select(value)
  web_object.select(value)
end

#select_value(value) ⇒ Object

Selects the option whose value attribute matches the provided string.



25
26
27
# File 'lib/symbiont/web_objects/select_list.rb', line 25

def select_value(value)
  web_object.select_value(value)
end

#selected?(value) ⇒ Boolean

This method returns true if any of the text or the label of any option that is selected matches the provided value.

Parameters:

  • value (String, Regexp)

    A value to check for

Returns:

  • (Boolean)


59
60
61
# File 'lib/symbiont/web_objects/select_list.rb', line 59

def selected?(value)
  web_object.selected? value
end

#selected_optionsArray<String>

This method returns an array of strings that contain the text of the currently selected options in a select list.

Returns:

  • (Array<String>)


44
45
46
# File 'lib/symbiont/web_objects/select_list.rb', line 44

def selected_options
  web_object.selected_options.map { |e| e.text }.compact
end

#selected_valuesArray<String>

This method returns an array of strings that contain the values of the currently selected options in a select list.

Returns:

  • (Array<String>)


51
52
53
# File 'lib/symbiont/web_objects/select_list.rb', line 51

def selected_values
  web_object.selected_options.map { |e| e.value }.compact
end