Alternatives to Click - Select and Focus
Posted: 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
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