【问题标题】:Unable to interact with Windows file upload box with watir无法与带有 watir 的 Windows 文件上传框交互
【发布时间】:2015-01-09 19:49:27
【问题描述】:

我正在编写一个 watir-webdriver 测试脚本来将文件上传到应用程序。我的应用程序使用剑道小部件,例如以下 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)

【问题讨论】:

  • 没有<input type="file"> 标签?如果有,#file_field 可能会成功。
  • 是的,它不存在,我能够通过多线程找到解决方案。

标签: watir watir-webdriver


【解决方案1】:
 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

【讨论】:

  • 你能解释一下什么是WIN32OLE吗?!
  • 我怎样才能在 debian (linux) 上做同样的事情??
猜你喜欢
  • 1970-01-01
  • 2019-12-28
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-06-22
  • 1970-01-01
  • 2013-03-25
  • 2011-10-07
相关资源
最近更新 更多