How to simulate “mouse over” (TestComplete)

Categories: How toSource code

Description

“Mouse Over” event triggers responses like highlighting, pop-up hints, etc.

  • With TestComplete we can use one of GUI object’s methods - HoverMouse - to simulate mouse over by placing mouse cursor over object.
  • Alternatively, we can use LLPlayer object to simulate mouse moves.

In the example provided both methods are simulating mouse overs on Google Search page.

Implementation

 Dim PropNames, PropValues, IEProcess
 Dim objSearch1, objSearch2
 Dim Iter
 'Before running this code example make sure Google Search page is up in IE
 PropNames = Array("processname", "index")
 PropValues = Array("iexplore", 1)
 Set IEProcess = Sys.FindChild(PropNames, PropValues, 1, True)
 If Not IEProcess.Exists Then
 'not found - exit
 End If
 ' "Google Search" button
 PropNames = Array("ObjectType", "ObjectIdentifier")
 PropValues = Array("SubmitButton", "btnK")
 Set objSearch1 = IEProcess.FindChild(PropNames, PropValues, 100, True)
 If Not objSearch1.Exists Then
 'not found - exit
 End If
 ' "I'm Feeling Lucky" button
 PropNames = Array("ObjectType", "ObjectIdentifier")
 PropValues = Array("SubmitButton", "btnI")
 Set objSearch2 = IEProcess.FindChild(PropNames, PropValues, 100, True)
 If Not objSearch2.Exists Then
 'not found - exit
 End If
 '1st method
 For Iter = 1 To 2
 objSearch1.HoverMouse
 aqUtils.Delay 500
 objSearch2.HoverMouse
 aqUtils.Delay 500
 Next
 '2nd method
 For Iter = objSearch1.ScreenLeft To objSearch1.ScreenLeft+objSearch1.Width
 Call LLPlayer.MouseMove(Iter, objSearch1.ScreenTop+Int(objSearch1.Height/2), 10)
 Next

Creative Commons Attribution-NonCommercial-NoDerivs 3.0 Unported
This work by the author is licensed under a Creative Commons Attribution-NonCommercial-NoDerivs 3.0 Unported.