Issue with accessing data of a Wpf Cell in datagrid

Technology specific object identification, supported applications, web technologies, and 3rd party controls.
kam
Posts: 10
Joined: Tue Sep 08, 2015 12:08 pm

Issue with accessing data of a Wpf Cell in datagrid

Post by kam » Tue Sep 08, 2015 12:51 pm

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.

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

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

Post by odklizec » Wed Sep 09, 2015 8:24 am

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.
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

kam
Posts: 10
Joined: Tue Sep 08, 2015 12:08 pm

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

Post by kam » Wed Sep 09, 2015 9:09 am

Thanks odklizec, I was able to reduce snapshot size with your suggested link.

I have it attached now.

My regards.
Attachments
Snapshot.rxsnp
(926.08 KiB) Downloaded 70 times
Last edited by kam on Wed Sep 09, 2015 9:40 am, edited 1 time in total.

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

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

Post by odklizec » Wed Sep 09, 2015 9:13 am

It seems you forgot to attach it ;)
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

kam
Posts: 10
Joined: Tue Sep 08, 2015 12:08 pm

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

Post by kam » Thu Sep 10, 2015 9:00 am

Hi Odklizec,

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

Kind regards.

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

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

Post by odklizec » Thu Sep 10, 2015 9:23 am

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
WrongPath.png (50.82 KiB) Viewed 2015 times
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.
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

kam
Posts: 10
Joined: Tue Sep 08, 2015 12:08 pm

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

Post by kam » Thu Sep 10, 2015 10:28 am

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.

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

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

Post by odklizec » Thu Sep 10, 2015 11:28 am

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
WPFPluginSettings.png (20.79 KiB) Viewed 2007 times
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 ;)
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

kam
Posts: 10
Joined: Tue Sep 08, 2015 12:08 pm

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

Post by kam » Thu Sep 10, 2015 3:09 pm

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.

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

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

Post by odklizec » Thu Sep 10, 2015 3:25 pm

Cool! Thanks for sharing your solution. I completely forgot about Copy&Paste ;)
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

smohanty78
Posts: 23
Joined: Tue Feb 10, 2015 10:51 am

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

Post by smohanty78 » Mon Oct 12, 2015 8:40 am

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