Element.State problem

Class library usage, coding and language questions.
Marianne Jacobsen
Posts: 44
Joined: Fri Oct 26, 2007 1:18 pm

Element.State problem

Post by Marianne Jacobsen » Fri Oct 26, 2007 4:36 pm

I'm trying to wait for an element to get into a state. More specific I'm waiting for an element to go from "unavailable" state to "normal" state.

My problem is that when I compare the state of the element to another state (like element.state.compareTo(anotherstate)) I can see that element.state really isn't a state but a number.

Code: Select all

                
while (element.State.CompareTo((State)Enum.Parse(typeof(Ranorex.State),"normal", true)) != 0)
{ //do something like wait     }
This while-loop will never end since the statement will never equal 0 even though the element becomes "normal".

What I can see in my code is that when element.State is "normal" it returns 1048580 and when it's "unavailable" it returns 1048577.

I'm working with custom .net controls so that might be the problem but I just want to make sure.

Right now I'm working around the problem by converting the number into a state manually - but I'd like very much not to do this.

Thanks for your support.

Marianne Jacobsen
Posts: 44
Joined: Fri Oct 26, 2007 1:18 pm

Post by Marianne Jacobsen » Fri Oct 26, 2007 5:19 pm

I've realised that the code/number returned is a bitwise or of several states. 1048577 must be unavailable and focusable.

But I think your code has a problem - why is 0 and 1 defined? Shouldn't that be only 1? Otherwise you'll have problems with AND operations.

Also the State.ToString() does not return all the states like (focusable, unavailable) but just the bitvalue.

Problem with FlagsAttribute I think.

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

Post by Support Team » Sun Oct 28, 2007 10:41 pm

The State field specifies values representing possible states for an element.
This enumeration has a FlagsAttribute attribute that allows a bitwise combination of its member values.

You can use the State property as follows:

Code: Select all

if ((child.State & State.Selected) != 0) 
    Console.WriteLine("selected = " + child.Name); 

if ((child.State & State.Collapsed) != 0)
    Console.WriteLine("collapsed = " + child.Name);

if (child.State == State.Normal)
    Console.WriteLine("no special state = " + child.Name);
Jenö
Ranorex Support Team

Marianne Jacobsen
Posts: 44
Joined: Fri Oct 26, 2007 1:18 pm

Post by Marianne Jacobsen » Tue Oct 30, 2007 9:14 am

Thank you for your answer. I can use the code as you supplied but I still think you should make corrections to the code.

Your State enum does not have the FlagsAttribute so the ToString() does not write out the string of each enumerator - instead it returns the binary value.

So if the state of an element is focusable and unavailable then calling ToString() gives me "1048577" - if the FlagsAttribute was set then calling ToString would give me "Focusable, Unavailable".

If you want the ToString() to return the value instead of real states then I rest my case - otherwise I think you should change it.

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

Post by Support Team » Tue Oct 30, 2007 9:29 am

You're perfectly right! The 'State' enum was missing the Flags Attribute in Ranorex 1.2. This Bug is fixed in the 1.3 release.

I know that the 'Normal' state is a bit confusing as it should be named 'None', but the naming is following the MS Accessibility state constants.

Regards,

Alex
Ranorex Support Team

Marianne Jacobsen
Posts: 44
Joined: Fri Oct 26, 2007 1:18 pm

Post by Marianne Jacobsen » Tue Oct 30, 2007 10:36 am

Thank you very much for the fast support - really top notch. Also nice to hear the explanation to the "Normal = 0" that actually had me confused.