我叫陈永达,欢迎来到我的51testing空间! 才开始使用,想把关于软件测试的一些资料和心得保存于此。 欢迎大家多来参观,多提宝贵意见!

【QTP】使用SendKeys来模拟键盘按键

上一篇 / 下一篇  2012-10-22 13:51:11 / 个人分类:QTP

       测试的过程中,经常会遇到这样的情况:

1.    需要使用到一些按键的操作,如按EnterF1什么的情况;

2.    需要模拟组合键的情况,如按Ctrl+A什么的;

3.    需要无法识别的控件中输入一些东西。

在这时候就可以使用SendKeys来进行模拟按键的操作。

      先上一个例子:

Dim WshShell
Set WshShell = CreateObject("WScript.Shell")

WshShell.SendKeys "{ENTER}"

如果要发送的是一个字符串,就可以:

 WshShell.SendKeys "hello"

如果是一些组合按钮,如:ShiftCtrlAlt,可用特殊字符代替:

 WshShell.SendKeys "+"       '按Shift

WshShell.SendKeys "^"       '按Ctrl

WshShell.SendKeys "%"       '按Alt

WshShell.SendKeys "^s"      '按Ctrl+S进行保存的操作

       如果是一些特殊的按键,如空格什么的:

 WshShell.SendKeys "{ENTER}"       '按回车

WshShell.SendKeys "{UP}"           '按光标向上

WshShell.SendKeys "{LEFT}"         '按光标向左

WshShell.SendKeys "{F1}"           '按F1

       用这个方法就能模拟一些按键的操作。

      但是这个方法好像无法模拟出输入中文,只能模拟键盘按英文键。



TAG: 软件测试 QTP sendkeys SendKeys Sendkeys 模拟键盘 陈永达

 

评分:0

我来说两句

Open Toolbar