Class: Selenium::WebDriver::Elements::FileChooser

Inherits:
Element
  • Object
show all
Defined in:
lib/selenium/webdriver/elements/file_chooser.rb

Instance Method Summary collapse

Methods inherited from Element

#create_element, #element_present?, #find_element, #find_elements, #method_missing

Constructor Details

#initialize(element, browser) ⇒ FileChooser

Returns a new instance of FileChooser.



11
12
13
14
15
16
# File 'lib/selenium/webdriver/elements/file_chooser.rb', line 11

def initialize element, browser
  super element, browser
  unless element.tag_name == 'input' and element.attribute('type') == 'file'
    raise TypeError.new "Can't create Chooser decorator for #{element.inspect}"
  end
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Selenium::WebDriver::Elements::Element

Instance Method Details

#autoitObject



31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/selenium/webdriver/elements/file_chooser.rb', line 31

def autoit
  autoit = Thread.new do
    AutoItX3::Window.wait "Open"
    dialog = AutoItX3::Window.new "Open"
    dialog.activate
    dialog.wait_active
    AutoItX3::Edit.new("Open", "", "Edit1").text = filename
    AutoItX3::Button.new("Open", "", "Button1").click
  end
  @element.click
  autoit.join
end

#choose_file(filename) ⇒ Object



18
19
20
21
22
23
# File 'lib/selenium/webdriver/elements/file_chooser.rb', line 18

def choose_file filename
  case @browser.browser
    when :chrome then raise "Chrome not supported"
    else @element.send_keys filename
  end
end

#populate(data) ⇒ Object



25
26
27
28
29
# File 'lib/selenium/webdriver/elements/file_chooser.rb', line 25

def populate data
  if data != nil
    choose_file data
  end
end