Seemingly Stuck in a Winforms GridView

Technology specific object identification, supported applications, web technologies, and 3rd party controls.
mcs
Posts: 29
Joined: Mon Aug 11, 2014 5:00 pm
Location: Portsmouth, NH

Seemingly Stuck in a Winforms GridView

Post by mcs » Wed Dec 10, 2014 10:29 pm

I've been trying to figure this out for two days now and, rather than completely drive myself crazy (although there are some, I'm sure, who would argue that I've been in that state for years), I thought I'd post my issue here and hope that someone can figure out what I'm missing.

I am working with an ordinary Winforms GridView which looks like this:
TestApp.png
TestAppScreenShot
TestApp.png (11.03 KiB) Viewed 1212 times
When the value in the Outcome column is "Inconclusive", I want to click on the Notes button which is at the rightmost of each row. The problem that I'm having is that no matter where the Outcome is "Inconclusive" the Notes button clicked is always that on the first row; I need to click on the button corresponding to the row where "Inconclusive" is found.

Here is my code which works fine at iterating and finding the "Inconclusives" but does not select the correct Notes button; I, also, edited my repository item (included below) so that it will be row inspecific; in fact, when I edit it in Spy, it highlights both Note button objects but, from the repository it only highlights the first one...

My code:

Code: Select all

string strHeaderName = "Outcome";
					
IList<Ranorex.Cell> myCellList = t.Find<Ranorex.Cell>(".//cell[@accessiblename~'" + strHeaderName  + "']");
					
foreach(Cell cell in myCellList )
     {
          if(!cell.IsHeader && cell.Text == "Inconclusive" || cell.Text == "Failed")
          {
	     repo.TFSTestRun.TestRunPage.NoteButton.Click();
	     repo.Notes.NoteText.PressKeys(notesComment);
	     repo.Notes.Save.Click();
	     WinForms.SendKeys.SendWait("{Tab}");
           }
     }
Here is my repository item's Rx Path:
.//table[@controltypename='TestStepsDataGridView']//cell[@accessiblevalue='System.Drawing.Bitmap']

If anyone can help point out the error of my ways, I will greatly appreciate it.
Thanks,
Mike
TestApp.png
TestAppScreenShot
TestApp.png (11.03 KiB) Viewed 1212 times

User avatar
odklizec
Ranorex Guru
Ranorex Guru
Posts: 3921
Joined: Mon Aug 13, 2012 9:54 am
Location: Zilina, Slovakia

Re: Seemingly Stuck in a Winforms GridView

Post by odklizec » Wed Dec 10, 2014 11:34 pm

Hi,

I think the problem is in the note button rxpath, which is not unique enough. I'm sure that if you put this path to the Ranorex Spy, there will be highlighted all note buttons in the grid view? And this is why your code clicks the first one. If there are found multiple items with the same rxpath, Ranorex uses the first one. What you need to do is to associate the click action with appropriate "note button" lying in the same row as is the found "inconclusive" cell.

Could you please post the snapshot file of the grid view in question? Here is how to create one...
http://www.ranorex.com/support/user-gui ... files.html
Pavel Kudrys
Ranorex explorer at Descartes Systems

Please add these details to your questions:
  • Ranorex Snapshot. Learn how to create one >here<
  • Ranorex xPath of problematic element(s)
  • Ranorex version
  • OS version
  • HW configuration

mcs
Posts: 29
Joined: Mon Aug 11, 2014 5:00 pm
Location: Portsmouth, NH

Re: Seemingly Stuck in a Winforms GridView

Post by mcs » Thu Dec 11, 2014 3:00 pm

Here (attached) is a snapshot of my gridview. Thanks!

odklizec, I do understand what you're saying... I guess that I am just unsure as to how to make the connection from code to repository to select the note button in the proper row. I would think that using a variable in the repository for the element's rowIndex would be the way to go but I'm not quite clear as to how to implement that in my user code.
Attachments
TestStepsGridView.rxsnp
TestStepsGridView_Snapshot
(59.77 KiB) Downloaded 81 times

User avatar
odklizec
Ranorex Guru
Ranorex Guru
Posts: 3921
Joined: Mon Aug 13, 2012 9:54 am
Location: Zilina, Slovakia

Re: Seemingly Stuck in a Winforms GridView

Post by odklizec » Tue Dec 16, 2014 9:44 am

Hi,

Sorry for the delay with my reply. Have you found a solution for your problem?

As I expected, your note button rxpath finds all instances of the note button...
note_path.png
note_path.png (57.55 KiB) Viewed 1160 times
What you need to do is to create a new module variable, let's say rowIndex. Then in the repository editor change note button path to this:

Code: Select all

//cell[@accessiblevalue='System.Drawing.Bitmap' and @rowindex=$rowIndex]
Now add this line to your user code:
rowIndex=cell.RowIndex.ToString();
so the code should look like this:

Code: Select all

          if(!cell.IsHeader && cell.Text == "Inconclusive" || cell.Text == "Failed")
          {
             rowIndex=cell.RowIndex.ToString(); // this sets the rowIndex module variable with actual cell RowIndex value
             ...
Then the click should be performed on the correct note buttons.

The only problem I see is that in the snapshot you published are all cell RowIndex values empty?
RowIndex-empty.png
RowIndex-empty.png (58.76 KiB) Viewed 1160 times
Could you please check your Ranorex WPF settings? Here are my settings and RowIndex is always set with correct value. So either your settings are different or your WPF control is incorrectly implemented?
wpf_settings.png
wpf_settings.png (24.17 KiB) Viewed 1160 times
Hope this helps?
Pavel Kudrys
Ranorex explorer at Descartes Systems

Please add these details to your questions:
  • Ranorex Snapshot. Learn how to create one >here<
  • Ranorex xPath of problematic element(s)
  • Ranorex version
  • OS version
  • HW configuration

mcs
Posts: 29
Joined: Mon Aug 11, 2014 5:00 pm
Location: Portsmouth, NH

Re: Seemingly Stuck in a Winforms GridView

Post by mcs » Tue Dec 16, 2014 3:47 pm

Thank you for your reply.
No, I haven't found a solution yet but had to move on to another project briefly which rescued me from banging my head on my desk. :wink:

I will try out what you've outlined which, I believe, is what I was missing... thanks!

However, it's true that, except for the header row which has a row index of -1, the other rows do not show a row index value in spy. My settings appear to be fine. This is, I believe, a win32 .NET form and not WPF, though.

Perhaps I can convince Ranorex to force the app to believe that it has row indexes where they do not appear... :D

Thanks again,
Mike