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
Alternatives to Click - Select and Focus
- Support Team
- Site Admin
- Posts: 12145
- Joined: Fri Jul 07, 2006 4:30 pm
- Location: Houston, Texas, USA
- Contact:
Re: Alternatives to Click - Select and Focus
Hi,
Maybe the easiest way to solve your problem is to set the value of the cell directly. This can be done as follows:
Kind Regards,
Larissa
Ranorex Support Team
Just because an item is selected it doesn't mean that it has the focus and vice versa.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?
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");
Larissa
Ranorex Support Team
Re: Alternatives to Click - Select and Focus
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
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
- Support Team
- Site Admin
- Posts: 12145
- Joined: Fri Jul 07, 2006 4:30 pm
- Location: Houston, Texas, USA
- Contact:
Re: Alternatives to Click - Select and Focus
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
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