方法一:
def
upload(locator,value)
thrd = Thread.new do
system("rubyw -e \"require
'win32ole';sleep 1; @autoit=WIN32OLE.new('AutoItX3.Control');
waitresult=@autoit.WinWait '选择文件', '', 15; sleep 1; if waitresult == 1\" -e
\"@autoit.ControlSetText '选择文件', '', 'Edit1', '#{value}'; @autoit.ControlSend '选择文件', '', 'Button2',
'{ENTER}';\" -e \"end\"")
end
remote_control_command("click",
[locator,])
thrd.join(1)
End
方法二:
POPUP_TITLES = ["选择文件", "Choose file", "Choose File to Upload"]
def upload(locator,value)
if @browser_string=="*iexplore"
begin
thr=Thread.new do
sleep 1
system(%Q{rubyw -e '
require "win32ole"
@autoit=WIN32OLE.new("AutoItX3.Control")
time=Time.now
while(Time.now - time)<15 do
#{POPUP_TITLES.inspect}.each do |popup_title|
next unless @autoit.WinWait popup_title, "", 1
@autoit.ControlSetText "选择文件", "", "Edit1", #{value.inspect}
@autoit.ControlSend "选择文件", "", "Button2", "{ENTER}"
end
end
'}
)
end
thr.join(1)
rescue => e
puts "function upload: #{e}"
end
remote_control_command("click", [locator])
else
self.type(locator, value)
end
end2.https的安全窗口
POPUP_SECURITY_TITLES = ['安全警报']
def open_https(url)
begin
if url=~/^https:/i
thr=Thread.new do
system(%Q{rubyw -e "
require 'win32ole'
sleep 0.5
@autoit=WIN32OLE.new('AutoItX3.Control')
time = Time.now
while(Time.now-time)<15
#{POPUP_SECURITY_TITLES.inspect}.each do |popup_title|
next unless @autoit.WinWait(popup_title, "", 1) == 1
@autoit.Controlfocus popup_title, '', 'Button1'
@autoit.ControlSend popup_title, '', 'Button1', '{SPACE}'
end
end
}
)
end
thr.join(1)
end
rescue => e
puts "function open: #{e}"
end
remote_control_command("open", [url,])
end希望能给你带来帮助。