At times we have to right click on an object (Links, Table Contents etc.) to bring up its context menu from which we can select any one option. It seems very straight when we do the task manually, but simulating the mouse click through scripting is not as simple. The following example demonstrates how to do it.
Suppose there is a link in a page named “Document”. By right clicking over the link we get a menu where we have an option “CreateDocument” to create a new document. Each option in the menu belongs to WebElement class. The code below helps us do it:
Set pathObj = Browser(“BrowserName”).Page(“Name”) // Assign the path to an object
Set deviceReplay = CreateObject(“Mercury.DeviceReplay”) //Create an object of DeviceReplay class which helps us simulate mouse click operation
getX = pathObj.Link(“Document”).GetROProperty(“abs_x”) // Get the X-axis value of the link
getY = pathObj.Link(“Document”).GetROProperty(“abs_y”) // Get the Y-axis value of the link
deviceReplay.MouseClick getX,getY,RIGHT_MOUSE_BUTTON // Simulates the right click operation over the link
pathObj.WebElement(“name:=CreateDocument”).Click // Click on the “CreateDocument” option.