Executing right-button mouse clicks

Class library usage, coding and language questions.
chall
Posts: 15
Joined: Mon Aug 20, 2007 4:15 pm

Executing right-button mouse clicks

Post by chall » Tue Aug 21, 2007 9:14 pm

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

admin
Site Admin
Site Admin
Posts: 350
Joined: Wed Jul 05, 2006 7:44 pm

Post by admin » Tue Aug 21, 2007 10:30 pm

Methods used: Form.FindControlName(); Form.Element.FindChild(); and Mouse.ClickContro() or Mouse.ClickElement().
Which Ranorex Version do you use?
Could you post your exact sample code please?

Jenö
Ranorex Team

chall
Posts: 15
Joined: Mon Aug 20, 2007 4:15 pm

Post by chall » Tue Aug 21, 2007 11:06 pm

I use the evaluation copy. Here is the code that I use:

ListView list = aForm.Element.FindChild(Role.List, "listViewName");
Element listItem = list.Element.FindChild(Role.ListItem, "listItem");

Mouse.ClickElement(listItem, MouseButtonType.RightButton);

admin
Site Admin
Site Admin
Posts: 350
Joined: Wed Jul 05, 2006 7:44 pm

Post by admin » Tue Aug 21, 2007 11:48 pm

Interesting. We have no known issues similar like this one at the moment.

Can you please check the Location and Size property of the ListView item?
Are they correct?

Jenö
Ranorex Team

chall
Posts: 15
Joined: Mon Aug 20, 2007 4:15 pm

Post by chall » Wed Aug 22, 2007 3:15 pm

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.

chall
Posts: 15
Joined: Mon Aug 20, 2007 4:15 pm

Post by chall » Wed Aug 22, 2007 3:24 pm

Using RanorexSpy and writing the value to the Console, I've verified that the size and location of the listView item are correct.

admin
Site Admin
Site Admin
Posts: 350
Joined: Wed Jul 05, 2006 7:44 pm

Post by admin » Wed Aug 22, 2007 4:08 pm

I call Mouse.MoveToElement(), which will always point to the listView item on which I want to perform the right click.
Can you please try the following code:

Code: Select all

Mouse.MoveToElement();
Mouse.Click(MouseButtonType.RightButton);
Jenö
Ranorex Team

chall
Posts: 15
Joined: Mon Aug 20, 2007 4:15 pm

Post by chall » Wed Aug 22, 2007 4:49 pm

I made a mistake in my description: it's when I invoke MouseToElement() that the cursor points to an unrelated item in another application. I've verified the control name, control ID, element name, and role are correct. Do you have any suggestions?

I apologize for my mistake.

admin
Site Admin
Site Admin
Posts: 350
Joined: Wed Jul 05, 2006 7:44 pm

Post by admin » Wed Aug 22, 2007 6:55 pm

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.
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)?

Jenö
Ranorex Team

chall
Posts: 15
Joined: Mon Aug 20, 2007 4:15 pm

Post by chall » Wed Aug 22, 2007 7:17 pm

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);
}

chall
Posts: 15
Joined: Mon Aug 20, 2007 4:15 pm

Post by chall » Wed Aug 22, 2007 7:59 pm

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.

admin
Site Admin
Site Admin
Posts: 350
Joined: Wed Jul 05, 2006 7:44 pm

Post by admin » Wed Aug 22, 2007 10:33 pm

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:

Code: Select all

if (listItem != null) 
{ 
    Mouse.ClickElement(listItem, MouseButtonType.RightButton, new Point(30,10));
}
This moves the mouse to the Point(30,10) relative to the left upper corner of the element.

Jenö
Ranorex Team

chall
Posts: 15
Joined: Mon Aug 20, 2007 4:15 pm

Post by chall » Wed Aug 22, 2007 11:04 pm

That did it! Thank you very much! How did you determine the point (30, 10)?

admin
Site Admin
Site Admin
Posts: 350
Joined: Wed Jul 05, 2006 7:44 pm

Post by admin » Wed Aug 22, 2007 11:23 pm

How did you determine the point (30, 10)?
My ListView item is 17 pixel height, i thought 10 will be OK for y and i used 30 for the x position.
But you can use other values also, the point is relative to the upper left corner of the element.

I put this issue to our todo list.

Jenö
Ranorex Team

chall
Posts: 15
Joined: Mon Aug 20, 2007 4:15 pm

Post by chall » Wed Aug 22, 2007 11:39 pm

I guess you're right. Before I read your solution, I used itemLocation.Offset(5, 3), Mouse.Move(itemLocation) and that worked for me. But I don't believe my solution will cover all situations.

Thanks again for your help, sir.