Class: Webdrone::Form

Inherits:
Object
  • Object
show all
Defined in:
lib/webdrone/form.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(a0) ⇒ Form

Returns a new instance of Form.



11
12
13
# File 'lib/webdrone/form.rb', line 11

def initialize(a0)
  @a0 = a0
end

Instance Attribute Details

#a0Object

Returns the value of attribute a0.



9
10
11
# File 'lib/webdrone/form.rb', line 9

def a0
  @a0
end

Instance Method Details

#clic(key, n: 1, visible: true) ⇒ Object



41
42
43
44
45
# File 'lib/webdrone/form.rb', line 41

def clic(key, n: 1, visible: true)
  self.find_item(key, n: n, visible: visible).click
rescue => exception
  Webdrone.report_error(@a0, exception, Kernel.caller_locations)
end

#get(key, n: 1, visible: true) ⇒ Object



35
36
37
38
39
# File 'lib/webdrone/form.rb', line 35

def get(key, n: 1, visible: true)
  self.find_item(key, n: n, visible: visible)[:value]
rescue => exception
  Webdrone.report_error(@a0, exception, Kernel.caller_locations)
end

#mark(key, n: 1, visible: true, color: '#af1616', times: 3, sleep: 0.05) ⇒ Object



47
48
49
50
51
# File 'lib/webdrone/form.rb', line 47

def mark(key, n: 1, visible: true, color: '#af1616', times: 3, sleep: 0.05)
  @a0.mark.mark_item self.find_item(key, n: n, visible: visible), color: color, times: times, sleep: sleep
rescue => exception
  Webdrone.report_error(@a0, exception, Kernel.caller_locations)
end

#set(key, val, n: 1, visible: true) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/webdrone/form.rb', line 22

def set(key, val, n: 1, visible: true)
  item = self.find_item(key, n: n, visible: visible)
  if item.tag_name == 'select'
    option = item.find_element :xpath, XPath::HTML.option(val).to_s
    option.click
  else
    item.clear
    item.send_keys(val)
  end
rescue => exception
  Webdrone.report_error(@a0, exception, Kernel.caller_locations)
end

#submit(key = nil, n: 1, visible: true) ⇒ Object



53
54
55
56
57
58
# File 'lib/webdrone/form.rb', line 53

def submit(key = nil, n: 1, visible: true)
  self.find_item(key, n: n, visible: visible) if key
  @lastitem.submit
rescue => exception
  Webdrone.report_error(@a0, exception, Kernel.caller_locations)
end

#with_xpath(xpath = nil, &block) ⇒ Object



15
16
17
18
19
20
# File 'lib/webdrone/form.rb', line 15

def with_xpath(xpath = nil, &block)
  @xpath = xpath
  instance_eval &block
rescue => exception
  Webdrone.report_error(@a0, exception, Kernel.caller_locations)
end

#xlsx(sheet: nil, filename: nil) ⇒ Object



60
61
62
63
64
65
66
# File 'lib/webdrone/form.rb', line 60

def xlsx(sheet: nil, filename: nil)
  @a0.xlsx.dict(sheet: sheet, filename: filename).each do |k, v|
    self.set k, v
  end
rescue => exception
  Webdrone.report_error(@a0, exception, Kernel.caller_locations)
end