Page 1 of 1

Issue with accessing data of a Wpf Cell in datagrid

Posted: Tue Sep 08, 2015 12:51 pm
by kam
I have written below lines of code in order to access data of a wpf cell in datagrid but no luck :(

I tried to attach Snapshot but couldn't due to size restriction.

Code: Select all

Container dataGrid = form.FindSingle<Container>("/form[@wpfnative='True' and @title='Hubble [DEMO900]' and @processname='Hubble']/container/container/?/?/container[@automationid='dockPanel']/?/?/tabpagelist/container/container[2]/container/element/container/container/container[2]/container[1]/container[@automationid='dataGridControl']/table[@automationid='dataGrid']/container[@automationid='centeringGrid']/container[@automationid='PART_RowsPresenter']", dur);
                
bool flag = false;
int count = dataGrid.Children.Count;
IList<Unknown> rows = dataGrid.Children;
                foreach (Unknown child in rows)
                {
                    Unknown cont = child.Children[0];
                    Unknown cellsCont = cont.Children[1];
                    IList<Cell> cellsList = cellsCont.FindChildren<Cell>();
                    foreach (Cell cell in cellsList)
                    {
                        cell.Click();
                        //string text = cell.Text;
                        //string text = cell.Element.GetAttributeValueText("AccessibleValue");
                        //CompressedImage comp  = cell.CaptureCompressedImage();
                        //comp.Store("C:\\Automation\\CompImage.png");
                    }
                }
I will be looking forward to your response.

Thanks.

Re: Issue with accessing data of a Wpf Cell in datagrid

Posted: Wed Sep 09, 2015 8:24 am
by odklizec
Hi and welcome here,

Are you able to track the problematic cell via Spy? Ranorex Snapshot of the WPF grid in question would be definitely helpful. In >this post< you can find how to reduce the size of snapshot.

Re: Issue with accessing data of a Wpf Cell in datagrid

Posted: Wed Sep 09, 2015 9:09 am
by kam
Thanks odklizec, I was able to reduce snapshot size with your suggested link.

I have it attached now.

My regards.

Re: Issue with accessing data of a Wpf Cell in datagrid

Posted: Wed Sep 09, 2015 9:13 am
by odklizec
It seems you forgot to attach it ;)

Re: Issue with accessing data of a Wpf Cell in datagrid

Posted: Thu Sep 10, 2015 9:00 am
by kam
Hi Odklizec,

I have re-attached snapshot since yesterday, and haven't seen any replies or solution to it yet.

Kind regards.

Re: Issue with accessing data of a Wpf Cell in datagrid

Posted: Thu Sep 10, 2015 9:23 am
by odklizec
Hi,

Unfortunately, you did not update your post after re-attaching the snapshot, so nobody probably noticed you added it ;)

As for your problem, it's most probably caused by the incorrect xpath used in your code. I tried it in the snapshot and sure enough, there are some missing/different elements in your app.
Original path:

Code: Select all

/form[@wpfnative='True' and @title='Hubble [DEMO900]' and @processname='Hubble']/container/container/?/?/container[@automationid='dockPanel']/?/?/tabpagelist/container/container[2]/container/element/container/container/container[2]/container[1]/container[@automationid='dataGridControl']/table[@automationid='dataGrid']/container[@automationid='centeringGrid']/container[@automationid='PART_RowsPresenter']
WrongPath.png
So what you need to do is to simplify your path, for example like this...

Code: Select all

/form[@wpfnative='True' and @title='Hubble [DEMO900]' and @processname='Hubble']/container/container/?/?/container[@automationid='dockPanel']/?/?/tabpagelist/container//container[@automationid='dataGridControl']/table[@automationid='dataGrid']//container[@automationid='PART_RowsPresenter']
If possible, you should avoid using element indexes in the xpath, because they are very unstable and prone to changes. Also, try to avoid name strings containing version numbers and similar numbers, which are likely to change (like [DEMO900]). You should either to remove them from the xpath or replace them with regular expression.

Re: Issue with accessing data of a Wpf Cell in datagrid

Posted: Thu Sep 10, 2015 10:28 am
by kam
Hello Odklizec,

Thanks for your response, much appreciated. Problem is not with RxPath and all your suggestions around building reliable rxpath have been noted.

I was able to click cell, but problem is that i couldn't get data copied out of the cell (please refer to below part of my previous code). Any of commented out part is what i need.

Code: Select all

foreach (Cell cell in cellsList)
                    {
                        cell.Click();
                        //string text = cell.Text;
                        //string text = cell.Element.GetAttributeValueText("AccessibleValue");
                    }
I'll be waiting for your response on this trend.

Thanks.

Re: Issue with accessing data of a Wpf Cell in datagrid

Posted: Thu Sep 10, 2015 11:28 am
by odklizec
Unfortunately, there seems to be no AccessibleValue (or any other attribute) holding the text of cell. At least I can't find anything in the provided snapshot. So there are two options you may try.

1) Go to Global Settings and here in Plugins tab, try to change the WPF Plugin settings.
WPFPluginSettings.png
See User Guide for more details about these settings. After closing the dialog, try to track a grid cell with Spy and verify if you can find the cell content.

2) If the above step does not help, your remaining hope is to add the whole Form to GDI access list. Once added, and if you are lucky, Ranorex should be able to detect the cell texts and display them in RAWText elements (displayed in the Spy tree).

Unfortunately, working with RAWTexts is pretty uncomfortable and the more the RAWText elements there is, the worse is to find what you are looking for. In other words, RAWTexts are good only for simple GUI elements and only in case of no other options left. Using it for GUI like Grid will be probably a nightmare ;)

Re: Issue with accessing data of a Wpf Cell in datagrid

Posted: Thu Sep 10, 2015 3:09 pm
by kam
Hi Odklizec,

I tried to implement 2 solutions you suggested but none of them worked for me; I so much appreciate your support.

I have now resolved it with 'copy' and 'paste' clipboard option as shown in below code.

Code: Select all

Container dataGrid = form.FindSingle<Container>("ranorex rxpath");
            bool flag = false;
            Object actualValue = 0;
            int count = dataGrid.Children.Count;
            IList<Unknown> rows = dataGrid.Children;
            foreach (Unknown child in rows)
            {
                Unknown cont = child.Children[0];
                Unknown cellsCont = cont.Children[1];
                IList<Cell> cellsList = cellsCont.FindChildren<Cell>();
                foreach (var cell in cellsList)
                {
                    cell.Click();
                    Keyboard.Press("{ControlKey DOWN}{ckey}");
                    Keyboard.Press("EscapeKey");
                    string actualData = Clipboard.GetText();
                    Console.WriteLine(actualData);            
                }
            }
This should hopefully work for anyone facing similar issue.

Kind regards,
Kam.

Re: Issue with accessing data of a Wpf Cell in datagrid

Posted: Thu Sep 10, 2015 3:25 pm
by odklizec
Cool! Thanks for sharing your solution. I completely forgot about Copy&Paste ;)

Re: Issue with accessing data of a Wpf Cell in datagrid

Posted: Mon Oct 12, 2015 8:40 am
by smohanty78
Hi
In global settings there is one option to select show all items .we can set it to true/false
If it false some of the objects are getting identified.
If it is true some other objects are getting identified.
Which option is good and suggested?
Please do suggest