Module: WatirRobot::List

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

Overview

Functionality related to ordered and unordered HTML lists

Instance Method Summary collapse

Instance Method Details

#get_list_items(loc, ordered = "false", sep = ";;") ⇒ Object

Get text from the items of a list

The second argument can be “true” or “false”; true for ordered list, false (default) for unordered.

Parameters:

  • loc (String)

    attribute/value pairs that match an HTML element

  • ordered (String) (defaults to: "false")

    true is ol, false is ul; strings for the booleans because the arguments come from Robot Framework

  • sep (String) (defaults to: ";;")

    the separator that should be used to separate the list items



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/watir_robot/keywords/list.rb', line 19

def get_list_items(loc, ordered = "false", sep = ";;")
  ordered = ordered.downcase unless ordered.nil?
  if ordered.nil?
    # TODO: Warn user about this ambiguity
    list = @browser.ul(parse_location(loc))
  elsif ordered == 'true'
    list = @browser.ol(parse_location(loc))
  elsif ordered == 'false'
    list = @browser.ul(parse_location(loc))
  else
    raise(ArgumentError, "If you specify ordered vs. unordered lists, the only valid values are 'true' or 'false' (case-insensitive)")
  end
  
  items = []
  list.lis.each do |item|
    items << item.text
  end
  
  items.join(sep)
end