Executing right-button mouse clicks
Executing right-button mouse clicks
Can someone tell me how to execute a right-button mouse click on a particular element or control?
Desired Situation: Open up windows explorer, find a specific list item in a list view, and execute a right-button mouse click on the element or control in order to display the typical pop-up window.
Result: I have no trouble finding the required elements or controls, but the cursor consistently leaves the windows explorer work area and right-clicks a completely unrelated item.
Methods used: Form.FindControlName(); Form.Element.FindChild(); and Mouse.ClickContro() or Mouse.ClickElement().
Please help,
Charles Hall
Desired Situation: Open up windows explorer, find a specific list item in a list view, and execute a right-button mouse click on the element or control in order to display the typical pop-up window.
Result: I have no trouble finding the required elements or controls, but the cursor consistently leaves the windows explorer work area and right-clicks a completely unrelated item.
Methods used: Form.FindControlName(); Form.Element.FindChild(); and Mouse.ClickContro() or Mouse.ClickElement().
Please help,
Charles Hall
To answer your question, "yes, I have checked the location of the listView item, but I have not checked its size property." Once I find the listView item, I write its name, class, and location to the Console in order to verify that they're the same values that RanorexSpy has.
Here are some of the other options that I've tried in order to resolve my issue: Using RanorexSpy, I determine the screen location of the listview item and pass that in as a parameter to Mouse.ClickElement(). When I call Mouse.ClickElement(), the cursor selects an item in another window or application. This is strange because before I invoke Mouse.ClickElement(), I call Mouse.MoveToElement(), which will always point to the listView item on which I want to perform the right click. It is only when I want to perform the right-click that Ranorex doesn't perform as expected.
Because of the strange results that I've encountered, I moved the cursor to the listView item, and used Mouse.Position as an argument for Mouse.ClickElement(). The results were the same: the cursor first points to the desired listView item and then clicks an unrelated item in another application. I've also tried setting Mouse.CoordinateMode to ActiveWindowCoordinates and ClientWindowCoordinates; neither option has worked.
Here are some of the other options that I've tried in order to resolve my issue: Using RanorexSpy, I determine the screen location of the listview item and pass that in as a parameter to Mouse.ClickElement(). When I call Mouse.ClickElement(), the cursor selects an item in another window or application. This is strange because before I invoke Mouse.ClickElement(), I call Mouse.MoveToElement(), which will always point to the listView item on which I want to perform the right click. It is only when I want to perform the right-click that Ranorex doesn't perform as expected.
Because of the strange results that I've encountered, I moved the cursor to the listView item, and used Mouse.Position as an argument for Mouse.ClickElement(). The results were the same: the cursor first points to the desired listView item and then clicks an unrelated item in another application. I've also tried setting Mouse.CoordinateMode to ActiveWindowCoordinates and ClientWindowCoordinates; neither option has worked.
Can you please try the following code:I call Mouse.MoveToElement(), which will always point to the listView item on which I want to perform the right click.
Code: Select all
Mouse.MoveToElement();
Mouse.Click(MouseButtonType.RightButton);
Ranorex Team
We would like to reproduce and debug this issue with the windows explorer, can you please post your source code (as short as possible please)?Open up windows explorer, find a specific list item in a list view, and execute a right-button mouse click on the element or control in order to display the typical pop-up window.
Jenö
Ranorex Team
Ranorex.Application.Start("explorer.exe");
Ranorex.Application.Sleep(1000);
Ranorex.Form form = Ranorex.Application.FindFormTitle("My Documents", SearchMatchMode.MatchExact, true, 1000);
form.Show();
form.Visible = true;
Ranorex.ListView listView = form.FindControlId(1);
Element listItem = listView.Element.FindChild(Role.ListItem, "SCJA.doc");
if (listItem != null)
{
Mouse.MoveToElement(listItem);
Mouse.ClickElement(listElement, MouseButtonType.RightButton);
}
Ranorex.Application.Sleep(1000);
Ranorex.Form form = Ranorex.Application.FindFormTitle("My Documents", SearchMatchMode.MatchExact, true, 1000);
form.Show();
form.Visible = true;
Ranorex.ListView listView = form.FindControlId(1);
Element listItem = listView.Element.FindChild(Role.ListItem, "SCJA.doc");
if (listItem != null)
{
Mouse.MoveToElement(listItem);
Mouse.ClickElement(listElement, MouseButtonType.RightButton);
}
I would like to add that the Mouse.Position is different from the listItem.location when using the Mouse.Move(listItem.location). The listItem location is displayed as 888,375; and although the Mouse.Position is the same as the listItem location, RanorexSpy displays the Mouse.Position as 888,168. This results in the incorrect popup menu being displayed.
Thank you for the sample, i think i know what the problem is.
Mouse.ClickElement clicks in the middle of the element, but calculates the x position with the whole width of the list view item.
If you have a scroll bar, than the x position can be wrong.
Please try the following code:
This moves the mouse to the Point(30,10) relative to the left upper corner of the element.
Jenö
Ranorex Team
Mouse.ClickElement clicks in the middle of the element, but calculates the x position with the whole width of the list view item.
If you have a scroll bar, than the x position can be wrong.
Please try the following code:
Code: Select all
if (listItem != null)
{
Mouse.ClickElement(listItem, MouseButtonType.RightButton, new Point(30,10));
}
Jenö
Ranorex Team