无法与带有watir的Windows文件上传框进行交互

时间:2015-01-09 19:49:28

标签: watir watir-webdriver

我正在编写一个watir-webdriver测试脚本来将文件上传到app。我的应用程序使用kendo小部件,例如下面 http://demos.telerik.com/kendo-ui/upload/index

当我调试代码时,我能够与Windows对话框进行交互,但是当我一起执行它时,它会超时,因为Windows对话框模式似乎永远不会得到焦点。代码如下:

require 'win32ole'

sleep 1
wsh = WIN32OLE.new('Wscript.Shell')
## open the windows dialog modal.
@browser.div(:class => "k-button k-upload-button").click

### Code times out after the above click, it never executes the below steps as app looses focus,     don't  know how I can switch the focus to windows modal and execute below code.

@browser.windows.last.use do   
  sleep 2
  wsh.AppActivate("File Upload")
  sleep 2
  wsh.SendKeys "{TAB}"
  sleep 1
  wsh.SendKeys("file path")
  sleep 1
  wsh.SendKeys "~"
end 

错误:

  

Net :: ReadTimeout(Net :: ReadTimeout)

1 个答案:

答案 0 :(得分:0)

 I was able to figure the solution for my problem by multi-threading .

 def threaded
   @filepath= upload_filepath ## reading from YAML
    t1=Thread.new { select_files }
    t2=Thread.new { file_upload(@filepath) }
    t1.join
    t2.join
  end

def select_files_click_button
    @browser.div(:class => "k-button k-upload-button").click
    sleep 2
 end

def file_upload(filepath)
  #def file_upload
    require 'win32ole'
    sleep 3
    wsh = WIN32OLE.new('Wscript.Shell')
    sleep 2
    wsh.AppActivate("File Upload")
    sleep 4
    wsh.SendKeys "{TAB}"
    sleep 3
    wsh.SendKeys("#{filepath}")
    sleep 2
    wsh.SendKeys "~"
    sleep 2
    @browser.windows.first.use
  end