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

#a0 ⇒ Object

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) ⇒ Object



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

def clic(key)
  self.find_item(key).click
end

#get(key) ⇒ Object



31
32
33
# File 'lib/webdrone/form.rb', line 31

def get(key)
  self.find_item(key)[:value]
end

#mark(key, color: 'red') ⇒ Object



39
40
41
# File 'lib/webdrone/form.rb', line 39

def mark(key, color: 'red')
  @a0.mark.flash self.find_item(key), color: color
end

#set(key, val) ⇒ Object



20
21
22
23
24
25
26
27
28
29
# File 'lib/webdrone/form.rb', line 20

def set(key, val)
  item = self.find_item(key)
  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
end

#submit(key = nil) ⇒ Object



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

def submit(key = nil)
  self.find_item(key) if key
  @lastitem.submit
end

#with_xpath(xpath, &block) ⇒ Object



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

def with_xpath(xpath, &block)
  @xpath = xpath
  instance_eval &block
end

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



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

def xlsx(sheet: nil, filename: nil)
  @a0.xlsx.dict(sheet: sheet, filename: filename).each do |k, v|
    self.set k, v
  end
end