Ranorex

Element.State problem

 
Post new topic   Reply to topic    Ranorex Forum Index -> RanorexNet
View previous topic :: View next topic  
Author Message
Marianne Jacobsen



Joined: 26 Oct 2007
Posts: 15

PostPosted: Fri Oct 26, 2007 5:36 pm    Post subject: Element.State problem
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: click into code to enlarge
               
while (element.State.CompareTo((State)Enum.Parse(typeof(Ranorex.State),"norm al", 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.
Back to top
View user's profile Send private message
Marianne Jacobsen



Joined: 26 Oct 2007
Posts: 15

PostPosted: Fri Oct 26, 2007 6:19 pm    Post subject:
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.
Back to top
View user's profile Send private message
Support Team
Site Admin


Joined: 07 Jul 2006
Posts: 435

PostPosted: Sun Oct 28, 2007 11:41 pm    Post subject:
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: click into code to enlarge
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
Back to top
View user's profile Send private message Visit poster's website
Marianne Jacobsen



Joined: 26 Oct 2007
Posts: 15

PostPosted: Tue Oct 30, 2007 10:14 am    Post subject:
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.
Back to top
View user's profile Send private message
Support Team
Site Admin


Joined: 07 Jul 2006
Posts: 435

PostPosted: Tue Oct 30, 2007 10:29 am    Post subject:
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
Back to top
View user's profile Send private message Visit poster's website
Marianne Jacobsen



Joined: 26 Oct 2007
Posts: 15

PostPosted: Tue Oct 30, 2007 11:36 am    Post subject:
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.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Ranorex Forum Index -> RanorexNet All times are GMT + 2 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum