What are the various methods to rightclick on a webelement in QTP?
By default QTP runs most steps on web elements using event replay this means that it sends DOM events to the underlying DOM element. When a person interacts with the web page the browser generates many DOM events (e.g. mousemove
mousedown
contextmenu
) and the web application may depend on any of these events in order to trigger the required behaviour. QTP does not know which events each web application will use and thus reproduces the subset that QTP's developers thought are interesting (for example for Click
QTP replays mousedown
, mouseup
and click
. For RightClick
there is also a contextmenu
event somewhere (I don't remember the order) and there is no click
.
The probable reason that what you tried in #2 failed is because there are additional events that the application expects which weren't created by QTP.
When you specify ReplayType=2
(as in case #3) you tell QTP's web package to use device replay this means that it physically moves the mouse to the requested location and performs the operation. This means that the browser thinks a real person is moving the mouse and will reproduce exactly the same events as it would when a human being is performing the operation.
You should have gotton exactly the same results with case #1 (explicitly using DeviceReplay
). I can think of two reasons why it still failed.
- In your code sample you have the line
'obj.MouseClick getX, getY,RIGHT_MOUSE_BUTTON
commented out, this is probably a copy/paste error but if this is also what you tried to run it would explain why nothing happened. - A more likely explanation is that you're using
abs_x
andabs_y
to replay the click, this is the top left corner of theWebElement
and perhaps this doesn't reach the correct DOM element. The way thatRightClick
in device replay mode differs from your implementation is that it clicks in the middle of theWebElement
(by default) try getting the width and height of the element and doing:obj.MouseClick getX+(width/2), getY+(height/2), RIGHT_MOUSE_BUTTON
There is another way to perform a right click and that would be:
webElem.Click micNoCoordinates, micNoCoordinates, micRightBtn
But I would recomend against it since webElem.RightClick
should work at least as well if not better.
Related videos on Youtube
Comments
-
Srittam about 2 years
I had to right click on a webelement. I tried the following methods:
For code simplicity assume
webElem
refers to a validBrowser().Page().WebElement()
.1)
Set obj=createobject("mercury.devicereplay") getX = webElem.GetROProperty("abs_x") getY = webElem.GetROProperty("abs_y") 'obj.MouseClick getX, getY,RIGHT_MOUSE_BUTTON
THE ABOVE CODE DID NOT WORK
2)
webElem.RightClick
THIS CODE DID NOT WORK EITHER
3) FOLLOWING CODE WORKED:
Setting.WebPackage("ReplayType") = 2 webElem.RightClick Setting.WebPackage("ReplayType") = 1
My questions are:
Why did I have to change the device replay type to make rightclick work? Where as, click method works fine.
Why, through
Mercury.DeviceReplay
object, theMouseClick
method did not work?How can I do this through
FireEvent
method? (please explainFireEvent
method in detail, FYI: I am new to QTP)What are the other methods to do this?
Could anyone please explain whay some methods work and some doesnt.
Thanks, Srittam
-
Srittam over 11 yearsHi @Motti , I could understand clearly about how QTP works when it clicks/right cliks. I also want to know, if there is any way to know what are the DOM events generated by browser for a DOM element. Also, from where I can find out the complete set of DOM events followed by QTP in order for various actions? I want to find out which event did QTP miss or did not do in order, so the expected action did not happen.
-
Motti over 11 years@Srittam you can trace DOM events with several tools (e.g. DHTMLSpy) and you can use the same method while running a QTP test to see which events are generated. Note that it may be that the event that is missing is on a different DOM element than that you have in the script in which case QTP won't fire it in event mode.