You are the best one!!

Ruby如何对 window进行操作

上一篇 / 下一篇  2009-02-18 12:08:47 / 个人分类:Ruby/Watir Space

在ruby/watir测试ie时,经常会有popup windows窗口,如何对那些windows窗口实现操作呢?

首先, require 'win32ole'。 这是windows的提供的接口。以下地址提供了每个function的用法:http://www.autoitscript.com/autoit3/docs/functions/ 

其次,讲一下基本思路:

1)new一个windows thread,

2)得到pop up window的控制,

3)操作window上的button.

以 Export File 为例:

    def savefile(filepath)
       autoit = WIN32OLE.new('AutoItX3.Control')      

       loop do
       ret = autoit.WinWait('File Download',2)  # Look for window with given title. 
       autoit.ControlFocus("File Download", "", "[CLASS:Button; INSTANCE:2]")
       sleep 1
       autoit.ControlClick("File Download", "", "[CLASS:Button; INSTANCE:2]", 1)
       autoit.WinWait('Save As',2)
       autoit.ControlSend('Save As', '', '[CLASS:Edit; INSTANCE:1]',filepath)
       sleep 1
       autoit.ControlClick('Save As', '', '[CLASS:Button; INSTANCE:2]', 'left')
       sleep 1
       if ret ==1 then return() end
      end
 end

调用方法:

    $ie.button(:id,'exportBtn').click_no_wait    #at this time, must use click_no_wait
    savefile('C:\file1.xls')

 

最后,AutoIt Window Info,这个工具可以用来识别windows窗口上的对象。

 

 


 


TAG:

 

评分:0

我来说两句

日历

« 2024-04-28  
 123456
78910111213
14151617181920
21222324252627
282930    

数据统计

  • 访问量: 29171
  • 日志数: 35
  • 文件数: 2
  • 书签数: 2
  • 建立时间: 2008-06-07
  • 更新时间: 2014-08-04

RSS订阅

Open Toolbar