51Testing软件测试论坛

标题: 这段QTP帮助中的代码没看明白,望指教 [打印本页]

作者: vincenthan    时间: 2007-11-30 18:37
标题: 这段QTP帮助中的代码没看明白,望指教
示例
以下示例在整个屏幕中搜索单词 Mercury,并在找到该单词时单击它。

l = -1

t = -1

r = -1

b = -1

Succeeded = TextUtil.GetTextLocation("16",0,l,t,r,b)

If Not Succeeded Then

MsgBox "找不到文本"

else

x = (l+r) / 2

y = (t+b) / 2

Set dr = CreateObject("Mercury.DeviceReplay")

dr.MouseClick x, y, 0

End If

其中的“16”是什么意思,怎么看都不懂,望大家指点
作者: lantianwei    时间: 2007-11-30 19:00
按照你的题意我觉得16应该换成"Mercury",不知道我说的对不对
作者: vincenthan    时间: 2007-12-3 10:13
更让我不解的是其中的Mercury对象,是什么意思,哪里能找到相关的帮助,希望高人能指教一下
作者: yzem99    时间: 2007-12-3 10:57
Set dr = CreateObject("Mercury.DeviceReplay")
我理解这个是设一个可以做回放操作的对象。
作者: jifeng    时间: 2007-12-3 11:12
哪来的这段文字阿?
我记得帮助里关于GetTextLocation不是这样描述的阿
作者: 板砖    时间: 2007-12-3 12:08
不懂.
作者: LittleDuck    时间: 2007-12-3 16:51
"Device Replay"是在提供坐标位置以后可以实现的鼠标和键盘操作。这个函数不能自动录制,需要在expert view中编程。
它有以下这些函数:
MouseMove x, y: Move the mouse to the screen coordinate (x,y).
MouseClick x, y, button: Move the mouse to the screen coordinate (x,y) and click the button(0=left; 1=middle; 2=right).
MouseDblClick x, y, button: Move the mouse to the screen coordinate (x,y) and double-click the button(0=left; 1=middle; 2=right).
DragAndDrop x, y, dropx, dropy, button: Drag the mouse from screen coordinate (x,y) to (dropx,dropy) with the button(0=left; 1=middle; 2=right) pressed.
PressKey key: Press a key using the ASCII code of the key.For example, Chr(13), vbCR and vbTab.
MouseDown x, y, button: Press the mouse button on screen coordinate (x,y).
MouseUp x, y, button: Release the mouse button on screen coordinate (x,y).
KeyDown key: Press a key using the ASCII code of the key.For example, Chr(13), vbCR and vbTab.
KeyUp key: Release a key using the ASCII code of the key.For example, Chr(13), vbCR and vbTab.
SendString string: Type a string.
作者: vincenthan    时间: 2007-12-3 18:01
关于我3楼的提问还是没懂
作者: walker1020    时间: 2007-12-3 21:35
查看一下帮助里面对 GetTextLocation的说明,不就明白了吗? 另外,楼主的代码是从哪里找到的?
作者: xazaj    时间: 2007-12-3 22:30
这段说明说的很详细了啊!
description:
Checks whether a specified text string is contained in a specified window area. If the

text string is located, the location coordinates are also returned.

描述:
检查特定的字符串是否存在指定的windows区域。如果这段字符串存在,就返回这个位置的坐标。


用法:
TextUtil.GetTextLocation(TextToFind, hWnd, Left, Top, Right, Bottom

[,MatchWholeWordOnly])

domo中的“16” 就是第一个参数 TextToFind

Argument :TextToFind
Type :    String  
Description :The text string you want to locate.  

参数:TextToFind
类型: 字符串
描述:你想定位的字符串。


这些帮助文档都有的哦,多查查再问比较好!加油!
作者: vincenthan    时间: 2007-12-4 18:20
看意思感觉是很好理解,但操作时发现不是那么回事啊,16我怀疑是帮助里面打错了吧,至于后面的Mercury对象应该是另一回事,谁能提供一个好的例子让我来实验一下,这个例子应该不是贴上就能运行的吧,反正我每次执行都只会显示找不到文本,不知道怎样才能找到




欢迎光临 51Testing软件测试论坛 (http://bbs.51testing.com/) Powered by Discuz! X3.2