从九十到一百很难,但是从零到九十很简单。

QTP中如何发送Key到应用程序?

上一篇 / 下一篇  2011-09-09 05:33:08 / 个人分类:QTP

最近碰到需要发送键盘输入快捷键来最小化和最大化浏览器,顺便总结下有哪些方法可以发送键盘输入。

 

  1. 使用.Type(key)来发送键盘输入

Eg. Browser(“test”).Page(“test”). Type micF5

 

  1. 使用Windows自带的SendKeys方法来输入组合键

1.下载安装Windows Scripting Host.
2.
创建对象
WScript.Shell
3.
激活浏览器

4.
使用SendKeys方法发送键盘操作(object.SendKeys(string)

 

 

Eg.

' This code executes the CTRL+F key combination (search) on a browser

' create shell object

set WshShell = CreateObject(“WScript.Shell”)

' Activate the browser window
WshShell.AppActivate "Put the label of the browser"

wait(3)
WshShell.SendKeys "^f" ' The caret (^) represents the CTRL key.
wait(2)

 

For more information on the SendKeys method, please refer to theMSDN SendKeys Methodpage.

 

  1. 使用Analog或者low-level recording来录制
  2. 使用Mercury Device Replay属性
    Step 1.   
    创建Device Replay对象.
    Step 2.   
    调用Device Replay的方法

    Step 3.   
    销毁Device Replay对象.

E.g:

‘Example to simulate F5 function key using DeviceReplay.

 Set bj = CreateObject("Mercury.DeviceReplay")
Window("Notepad").Activate
obj.PressKey VK_F5

 

 

     For more information on the Device Replay method, please refer to

http://www.advancedqtp.com/2008/04/the-undocumented-devicereplay/


TAG:

 

评分:0

我来说两句

日历

« 2024-05-15  
   1234
567891011
12131415161718
19202122232425
262728293031 

数据统计

  • 访问量: 6272
  • 日志数: 11
  • 建立时间: 2010-05-08
  • 更新时间: 2011-09-14

RSS订阅

Open Toolbar