Method: WatirRobot::Parser#parse_location
- Defined in:
- lib/watir_robot/parser.rb
#parse_location(loc) ⇒ Hash
(Non-Keyword) Parses the “location” string provided as argument for locating HTML elements.
Watir-WebDriver expects a hash of parameters by which to search for HTML elements. This function take arguments from Robot Framework tests in the form of attribute=value
and constructs a hash which Watir-WebDriver can use to uniquely identify HTML elements on the page.
117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 |
# File 'lib/watir_robot/parser.rb', line 117 def parse_location(loc) loc = self.trim_sides(loc) if loc[0..3].downcase == 'css=' return {:css => loc[4..loc.length]} elsif loc[0..5].downcase == 'xpath=' return {:xpath => loc[6..loc.length]} else # Comma-separated attributes attr_list = loc.split(',') attrs = {} attr_list.each do |a| attr_kv = a.split('=') # Need to turn strings in format "/regex-here/" into actual regexes if attr_kv[1].start_with?('/') attr_kv[1] = Regexp.new(Regexp.quote(attr_kv[1].gsub('/', ''))) end attr_kv[1] = self.trim_sides(attr_kv[1]) unless attr_kv[1].is_a? Regexp attrs[self.trim_sides(attr_kv[0])] = attr_kv[1] end # Watir expects symbols for keys attrs = Hash[attrs.map { |k, v| [k.to_sym, v] }] if attrs.key? :id attrs.delete_if {|k, v| k != :id} end return attrs end end |