MouseClick方法
描述
在指定的屏幕位置执行鼠标左键或右键的单击操作。
语法
object.MouseClick( x, y, Button )
参数
object : Mercury.DeviceReplay对象。
x :屏幕坐标X轴的值。
y :屏幕坐标Y轴的值。
Button :可能的值包括
LEFT_MOUSE_BUTTON = 0
MIDDLE_MOUSE_BUTTON = 1
RIGHT_MOUSE_BUTTON = 2
返回值
无。
例子
下面的例子在执行之前需要做一定的准备工作。例子的目的是在www.advancedqtp.com网站上执行DragAndDrop操作,如果在录制时执行拖拽操作,则不会被录制下来。因此这个例子是支持某些操作的例子。这个例子在IE环境下测试通过。
打开IE浏览器并导航到www.advancedqtp.com。这个例子会交换dbxhandle项,这些对象可以被拖拽以便满足个性化显示的要求。
打开QTP(加载Web插件),新建一个测试,打开对象库(object repository)并添加浏览器中的页面对象到本地对象库(local object repository)中。
重命名对象…
Option Explicit
Const LEFT_MOUSE_BUTTON = 0
Dim oWebElemDesc1, oWebElemDesc2
Dim oWebElem1, oWebElem2
Dim devRep
Dim nX1, nX2, nY1, nY2, nH1, nH2, hwnd
Dim point1, point2
' ** This class holds a point coordinate
Class Point
Private mX, mY
Property Let X( ByVal value )
mX = value
End Property
Property Get X()
X = mX
End Property
Property Let Y( ByVal value )
mY = value
End Property
Property Get Y()
Y = mY
End Property
End Class
' ** Retrieving the handle of the browser
hwnd = Browser("QTP").GetROProperty( "hwnd" )
Window( "hwnd:=" & hwnd ).Activate
' ** Create a description for 'Program Professionally'
Set oWebElemDesc1 = Description.Create()
oWebElemDesc1( "micclass" ).Value = "WebElement"
oWebElemDesc1( "html tag" ).Value = "H3"
oWebElemDesc1( "innertext" ).Value = "Program Professionally"
oWebElemDesc1( "class" ).Value = "dbx-handle dbx-handle-cursor"
' ** Create a description for 'Links'
Set oWebElementDesc2 = Description.Create()
oWebElemDesc2( "micclass" ).Value = "WebElement"
oWebElemDesc2( "html tag" ).Value = "H3"
oWebElemDesc2( "innertext" ).Value = "Links"
oWebElemDesc2( "class" ).Value = "dbx-handle dbx-handle-cursor"
' ** Searching for the elements
With Browser( "QTP" ).Page( "QTP" )
If .ChildObjects( oWebElemDesc1 ).Count = 1 Then
Set oWebElem1 = .WebElement( oWebElemDesc1 )
If .ChildObjects( oWebElemDesc2 ).Count = 1 Then
Set oWebElem2 = .WebElement( oWebElemDesc2 )
Else
Print "Web Element 'Program Professionally' was not found."
ExitTest( micFail )
End If
Else
Print "Web Element 'Program Professionally' was not found."
ExitTest( micFail )
End If
End With
' ** Retrieve elements dimensions
nX1 = oWebElem1.GetROProperty( "abs_x" )
nH1 = oWebElem1.GetROProperty( "height" )
nY1 = oWebElem1.GetROProperty( "abs_y" )
nX2 = oWebElem2.GetROProperty( "abs_x" )
nH2 = oWebElem2.GetROProperty( "height" )
nY2 = oWebElem2.GetROProperty( "abs_y" )
Set point1 = New Point
point1.X = nX1 + 10
point1.Y = nY1 + nH1 - 10
Set point2 = New Point
' ** Dragging up
If nY1 > nY2 Then
point2.X = nX2 + 20
point2.Y = nY2 + nH2 - 20
Else
' ** Dragging down
point2.X = nX2 + 20
point2.Y = nY2 + nH2 + 20
End If
Set devRep = CreateObject( "Mercury.DeviceReplay" )
devRep.DragAndDrop point1.X, point1.Y, _
point2.X, point2.Y, LEFT_MOUSE_BUTTON
MouseDbClick方法
描述
在指定的屏幕位置中执行鼠标左键或右键的双击事件。
语法
object.MouseDblClick( x, y, Button )
参数
object : Mercury.DeviceReplay对象。
x :屏幕坐标X轴的值。
y :屏幕坐标Y轴的值。
Button :可能的值包括
LEFT_MOUSE_BUTTON = 0
MIDDLE_MOUSE_BUTTON = 1
RIGHT_MOUSE_BUTTON = 2
返回值
无