How to get TreeItem text color

Ask general questions here.
Fent12
Posts: 11
Joined: Tue Mar 21, 2017 9:38 am

How to get TreeItem text color

Post by Fent12 » Fri Mar 24, 2017 4:26 am

I want to get TreeNode text color and backcolor,like node5,
i try like this ,but the object 'box_c' return null

Code: Select all

              string str_temp = "/form[@title='Form1' and @processname='test_tree' and @controltypename='Form1' and @instance='0']/container[@controlname='splitContainer1']/?/?/tree[@controlname='treeView1']//treeitem[@accessiblename='Node5']";

              Ranorex.TreeItem tree_item = null;
              bool aa = Host.Local.TryFindSingle<Ranorex.TreeItem>(str_temp, 5000, out tree_item);
              if (aa)
              {
                  object box_c = tree_item.Element.GetAttributeValue("BackColor"); // return null
                  Color cl = (Color)box_c;
              }
Some body know how to get the node text color and backcolor?
Attachments
tree_node_color.rxsnp
(20.79 KiB) Downloaded 25 times

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

Re: How to get TreeItem text color

Post by odklizec » Fri Mar 24, 2017 8:13 am

Hi,

If there is no BackColor attribute available in the Spy, then GetAttributeValue is most probably useless here ;) Try this code instead:

Code: Select all

Color color = tree_item.GetPropertyValue<Color>("BackColor"); 
If the above code fails, you will most probably have to use Invoke Remotely, to get the background color of the problematic element. Check for example this post:
http://www.ranorex.com/forum/get-backgr ... tml#p28331

And this blog post (somewhat old but still valid):
http://www.ranorex.com/blog/transfering ... t-control/
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

Fent12
Posts: 11
Joined: Tue Mar 21, 2017 9:38 am

Re: How to get TreeItem text color

Post by Fent12 » Fri Mar 24, 2017 10:16 am

odklizec,thanks for response

I try to the post you gived,
but when run ,it raise expection " The element does not support the required capability 'control'. "
do you know how to handle this ?

my code like below

Code: Select all

              string str_temp = "/form[@controlname='Form1']/container[@controlname='splitContainer1']/?/?/tree[@controlname='treeView1']//treeitem[@accessiblename='Node5']";
              Ranorex.TreeItem tree_item = null;
              bool aa = Host.Local.TryFindSingle<Ranorex.TreeItem>(str_temp, 5000, out tree_item);
              if (aa)
              {
                    Ranorex.TreeItem tree_item1 = str_temp;
                    Ranorex.Control myCtrl = (Ranorex.Control)tree_item1.Element;  //=>this raise exception
                    //"The element does not support the required capability 'control'."
                  ...

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

Re: How to get TreeItem text color

Post by odklizec » Fri Mar 24, 2017 10:36 am

Why do you use this (failing) line anyway? For obtaining text color from tree item, it should be enough to use tree_item element obtained from TryFindSingle method.
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

Fent12
Posts: 11
Joined: Tue Mar 21, 2017 9:38 am

Re: How to get TreeItem text color

Post by Fent12 » Fri Mar 24, 2017 11:02 am

odklizec,thanks for response

I only want to try the method in post that you gived;

Do you mean that ,the tree item (Node5) text color or back color can get from the var tree_item ?
can you know which API can get it ?

thks

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

Re: How to get TreeItem text color

Post by odklizec » Fri Mar 24, 2017 12:02 pm

I think this code should be enough to obtain the background color of provided tree element?...

Code: Select all

string str_temp = "/form[@controlname='Form1']/container[@controlname='splitContainer1']/?/?/tree[@controlname='treeView1']//treeitem[@accessiblename='Node5']";
              Ranorex.TreeItem tree_item = null;
              bool aa = Host.Local.TryFindSingle<Ranorex.TreeItem>(str_temp, 5000, out tree_item);
              Color color = tree_item.GetPropertyValue<Color>("BackColor"); 
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

Fent12
Posts: 11
Joined: Tue Mar 21, 2017 9:38 am

Re: How to get TreeItem text color

Post by Fent12 » Mon Mar 27, 2017 2:37 am

odklizec wrote:I think this code should be enough to obtain the background color of provided tree element?...

Code: Select all

string str_temp = "/form[@controlname='Form1']/container[@controlname='splitContainer1']/?/?/tree[@controlname='treeView1']//treeitem[@accessiblename='Node5']";
              Ranorex.TreeItem tree_item = null;
              bool aa = Host.Local.TryFindSingle<Ranorex.TreeItem>(str_temp, 5000, out tree_item);
              Color color = tree_item.GetPropertyValue<Color>("BackColor"); 
Thanks for response,
This code confuse me,this code can not complie,"'Ranorex.TreeItem' does not contain a definition for 'GetPropertyValue' "
I read the API document,this method only for the class of 'Ranorex.Control',not for TreeItem
Or my ranorex version lower?
which version do you used?

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

Re: How to get TreeItem text color

Post by odklizec » Mon Mar 27, 2017 7:55 am

Hi,

I'm using latest 6.2.1, however, I've not tried the above code. Simply, I don't have a sample app where I could try it ;) If you can provide such sample app, I may try it. It does not have to be the actual AUT. Just a small sample app with problematic tree control should be enough.

The above code should work. Try to search "GetPropertyValue<Color>" in this forum. It should return multiple posts discussing usage of this method. If the code does not work for you, then I'm afraid, your only hope is Invoke Remotely, as mentioned in another of my posts.
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

Fent12
Posts: 11
Joined: Tue Mar 21, 2017 9:38 am

Re: How to get TreeItem text color

Post by Fent12 » Mon Mar 27, 2017 9:04 am

odklizec wrote:Hi,

I'm using latest 6.2.1, however, I've not tried the above code. Simply, I don't have a sample app where I could try it ;) If you can provide such sample app, I may try it. It does not have to be the actual AUT. Just a small sample app with problematic tree control should be enough.

The above code should work. Try to search "GetPropertyValue<Color>" in this forum. It should return multiple posts discussing usage of this method. If the code does not work for you, then I'm afraid, your only hope is Invoke Remotely, as mentioned in another of my posts.
Thank you very much,
this is my sample app,that i want to get the text color and back color from the 'Node5'

And another, i try the posts that you give ,but find that the TreeItem can not translate to Ranorex.Control,the method GetPropertyValue() only for Ranorex.Control.
Attachments
test_tree.zip
(4.06 KiB) Downloaded 31 times

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

Re: How to get TreeItem text color

Post by odklizec » Tue Mar 28, 2017 7:34 am

Hi,

Unfortunately, I too was not able to convert the TreeItem into Control and hence neither the GetProperty, nor Invoke Remotely worked for me. I've tried something as described here:
http://www.ranorex.com/forum/get-backgr ... tml#p28331
and here:
http://www.ranorex.com/support/user-gui ... apter.html
But without luck. Maybe someone more knowledgeable in .net and Ranorex will suggest something useful? ;)
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

User avatar
Support Team
Site Admin
Site Admin
Posts: 11709
Joined: Fri Jul 07, 2006 4:30 pm
Location: Graz, Austria

Re: How to get TreeItem text color

Post by Support Team » Fri Mar 31, 2017 12:28 pm

Hi Fent12,

In order to analyze the issue it would be great if you could provide the VS solution of the sample application (test_tree.exe). I would suggest contacting [email protected] directly including the compressed VS solution.

We look forward to hearing from you.

Sincerely,
Johannes
.
Image