Alternatives to Click - Select and Focus

Technology specific object identification, supported applications, web technologies, and 3rd party controls.
LPG
Posts: 39
Joined: Mon Jul 25, 2011 6:12 pm

Alternatives to Click - Select and Focus

Post by LPG » Tue Jul 17, 2012 7:44 pm

Hi,

Sometimes when the Ranorex code (or recording) clicks on a cell in a table (grid) to enter a value, the value gets entered in a different cell than what we clicked on. The cells has tooltips that appears when you hover over them, and we suspect that the position of hovering tooltip is sometimes confusing things and causes Ranorex to click where the tooltip is showing instead of on the cell it was told to go to.

Either way, whatever the reason is, it seems that just clicking on a cell is not enough to make sure that is the cell that will be active to receive data entry. For example, my recording would do something like this:

Ranorex.Cell testCell = repo.MainForm.Grid1.CellDepth;
testCell.Click();
testCell.PressKeys("{1}{Return}");

but then the value 1 may end up in the cell next to it.

To make sure we enter the value into the correct cell, it seems that we need to use something else than Click(). The idea is to somehow get focus on the cell in question, and then press F2 to put it in Edit mode, and only then enter the value.

So first I tried this:
Ranorex.Cell testCell = repo.MainForm.Grid1.CellDepth;
testCell.Focus();
testCell.PressKeys("{F2}");
testCell.PressKeys("{1}{Return}");

However, this doesn't work. The Focus doesn't focus on testCell, but seems to Focus anywhere in the grid.

Then I tried this:
Ranorex.Cell testCell = repo.MainForm.Grid1.CellDepth;
testCell.Select();
testCell.PressKeys("{F2}");
testCell.PressKeys("{1}{Return}");

This only seems to work if the focus is currently in that grid. So, if we worked with a cell in a different grid right BEFORE the above code is executed, it enters the value in that cell. Which is not the cell the code is telling it to go to.

So, now I have this code:
Ranorex.Cell testCell = repo.MainForm.Grid1.CellDepth;
testCell.Focus();
testCell.Select();
testCell.PressKeys("{F2}");
testCell.PressKeys("{1}{Return}");

Or, the Focus and Select statement can be swapped too, it seems to work the same in either order. Which makes me wonder if I can trust this code to always behave as expected.

Is this really the best way achieve this? I'm wondering why Select does not work on its own without Focus. If you specify which cell it should Select already (as part of the repo selection), why do you need Focus to direct it to the right Grid as well?

Thank you

User avatar
Support Team
Site Admin
Site Admin
Posts: 11709
Joined: Fri Jul 07, 2006 4:30 pm
Location: Graz, Austria

Re: Alternatives to Click - Select and Focus

Post by Support Team » Wed Jul 18, 2012 10:25 am

Hi,
I'm wondering why Select does not work on its own without Focus. If you specify which cell it should Select already (as part of the repo selection), why do you need Focus to direct it to the right Grid as well?
Just because an item is selected it doesn't mean that it has the focus and vice versa.
Maybe the easiest way to solve your problem is to set the value of the cell directly. This can be done as follows:

Code: Select all

Ranorex.Cell testCell = repo.MainForm.Grid1.CellDepth;
testCell.Element.SetAttributeValue("Text","1");
Kind Regards,
Larissa
Ranorex Support Team
.
Image

LPG
Posts: 39
Joined: Mon Jul 25, 2011 6:12 pm

Re: Alternatives to Click - Select and Focus

Post by LPG » Wed Jul 18, 2012 11:12 pm

For some tests it should work to use SetAttributeValue. However, for other tests, it needs to be more "user entry" oriented. I think SetAttributeValue is moving away from being "user entry" oriented.

For example, verifying that you can only enter numeric values, and that you get an appropriate error message if you don't, should rather be more "user input" driven. Would a "Focus", "Select", and F2 to put it in edit mode be the best way for this type of situation?

Thanks

User avatar
Support Team
Site Admin
Site Admin
Posts: 11709
Joined: Fri Jul 07, 2006 4:30 pm
Location: Graz, Austria

Re: Alternatives to Click - Select and Focus

Post by Support Team » Thu Jul 19, 2012 10:21 am

If your program is well designed result should be the same, regardless of whether you perform a PressKeys or a SetValueAction. Maybe have a look at the action listener and the methods running in the background of your program to find out if there are some differences.

I would say SetValueAction is the more elegant way.
Nevertheless you can handle your problem with "Focus", "Select", and F2.

Regards,
Larissa
Ranorex Support Team
.
Image