If you are dealing with one of MSAA-based libraries you have two ways to
achieve the goal.
You may use State property of an object. This
property is a part of Win32Generic behavior pattern and any object has it. E.g.
RadioButton.
You may use GetStateString() method of
Accessible Object attached to an object.
In both cases you will need information about possible state values. You may
find it in MSDN article: http://msdn.microsoft.com/en-us/library/dd373609(v=VS.85).aspx
Let's look at each way in more detail. Assume that we have a check box with
name 'checkBox', and we want to determine its checked state and write it to
report.
State Property
The value of State property is an integer. We need to test its bits against
state constants.
Tester.Message("checkBox check state: " +
((SeS('checkBox').button.GetState() & 0x00000010) != 0));
GetStateString()
Method
This method returns a string where state constant names are separated by
commas. The string contains the name of a state constant only if the
corresponding state is set.
Tester.Message("checkBox check state: " +
(SeS('checkBox').button.AO().GetStateString().indexOf("STATE_SYSTEM_CHECKED")
!= -1));
Important Note
Be careful calling GetState() and GetStateString(). To get correct result
you need to understand the structure of the object. For example, if we consider
the Win32CheckButton matcher rule you will see:
behavior:[Win32CheckBox],
role: "ROLE_SYSTEM_WINDOW",
or_rules: [
{
role:
"ROLE_SYSTEM_CHECKBUTTON",
save_to: "button"
}
]
The object directly corresponding to the check button is saved to the
'button' property of the matched object. Thus if you make the call:
Tester.Message(SeS('checkBox').AO().GetStateString());
It will report the state of an accessible object corresponding to
"ROLE_SYSTEM_WINDOW", this state will never contain
"STATE_SYSTEM_CHECKED".
The correct call to make is:
Tester.Message(SeS('checkBox').button.AO().GetStateString());
It will report the state of an accessible object corresponding to
"ROLE_SYSTEM_CHECKBUTTON".
State Constants
Here is a list of state constants for your convenience:
public enum StateSystemConst
{
STATE_SYSTEM_UNAVAILABLE =
0x00000001,
STATE_SYSTEM_SELECTED = 0x00000002,
STATE_SYSTEM_FOCUSED = 0x00000004,
STATE_SYSTEM_PRESSED = 0x00000008,
STATE_SYSTEM_CHECKED = 0x00000010,
STATE_SYSTEM_MIXED = 0x00000020,
STATE_SYSTEM_READONLY = 0x00000040,
STATE_SYSTEM_HOTTRACKED = 0x00000080,
STATE_SYSTEM_DEFAULT = 0x00000100,
STATE_SYSTEM_EXPANDED = 0x00000200,
STATE_SYSTEM_COLLAPSED = 0x00000400,
STATE_SYSTEM_BUSY = 0x00000800,
STATE_SYSTEM_FLOATING = 0x00001000,
STATE_SYSTEM_MARQUEED = 0x00002000,
STATE_SYSTEM_ANIMATED = 0x00004000,
STATE_SYSTEM_INVISIBLE = 0x00008000,
STATE_SYSTEM_OFFSCREEN = 0x00010000,
STATE_SYSTEM_SIZEABLE = 0x00020000,
STATE_SYSTEM_MOVEABLE = 0x00040000,
STATE_SYSTEM_SELFVOICING =
0x00080000,
STATE_SYSTEM_FOCUSABLE = 0x00100000,
STATE_SYSTEM_SELECTABLE = 0x00200000,
STATE_SYSTEM_LINKED = 0x00400000,
STATE_SYSTEM_TRAVERSED = 0x00800000,
STATE_SYSTEM_MULTISELECTABLE =
0x01000000,
STATE_SYSTEM_EXTSELECTABLE =
0x02000000,
STATE_SYSTEM_ALERT_LOW = 0x04000000,
STATE_SYSTEM_ALERT_MEDIUM =
0x08000000,
STATE_SYSTEM_ALERT_HIGH = 0x10000000,
STATE_SYSTEM_PROTECTED = 0x20000000,
STATE_SYSTEM_HASPOPUP = 0x40000000,
STATE_SYSTEM_VALID = 0x7FFFFFFF
}