Method: Webdrone::Form#set

Defined in:
lib/webdrone/form.rb

#set(key, val, n: 1, visible: true, scroll: false, parent: a0.conf.parent, mark: false) ⇒ Object



93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
# File 'lib/webdrone/form.rb', line 93

def set(key, val, n: 1, visible: true, scroll: false, parent: a0.conf.parent, mark: false)
  item = find_item(key, n: n, visible: visible, scroll: scroll, parent: parent)
  @a0.mark.mark_item item if mark
  if item.tag_name == 'select'
    options = item.find_elements :xpath, Webdrone::XPath.option(val).to_s
    raise "option not found for value: #{val} " if options.empty?

    # Take the exact match, or the first one
    option = options.find do |elem|
      elem.text == val
    end
    option ||= options.first

    option.click
  else
    item.clear
    item.send_keys(val)
  end
  @data[key] = val if @data
  nil
rescue StandardError => error
  Webdrone.report_error(@a0, error)
end