How to get property like LegacyIAccessible.State: or Toggle.ToggleState: of CheckBox control
Hi,
I am working a POC with WPF application and trying to properties of checkbox control to check checkbox is checked or not and take a required action further. below is code where I am trying to other property of checkbox at runtime. WindowsElement cellObj = session.FindElementByAccessibilityId("Checkbox"); if (cellObj.GetAttribute("Toggle.ToggleState:").Contains("Off")) { cellObj.Click(); } In the above code , trying to get a attribute Toggle state or LegacyIAccessible.State: and see what is the state of checkbox. But this returns NULL all the time and for other attribute of checkbox as well. Is there something that I am doing wrong . Any suggestion welcome. :) Or Is This something WinAppDriver lacks as of now and any enhancements in next release?
regards, Mahi
Hi @Manvibha,
Can you please try the same approach that checkbox in UWP app is being tested below? https://github.com/Microsoft/WinAppDriver/blob/master/Tests/UWPControls/CheckBox.cs#L104
In UWP app a CheckBox UI control Selected property returns true when it is checked and false otherwise. E.g.
var originalState = checkBoxElement1.Selected;
checkBoxElement1.Click(); // Toggling the state
Assert.AreNotEqual(originalState, checkBoxElement1.Selected);
checkBoxElement1.Click(); // Toggling the state
Assert.AreEqual(originalState, checkBoxElement1.Selected);
Thanks A lot Timotiusmargo. It worked the way I wanted!!!
Regards, Mahi
I want to know the disable checkbox is checked or not but i am not getting the value either it is checked or not. i have used (LegacyIAccessible.State:) and Toggle.ToggleState it is showing always false what is the reason? my checkbox is actually disabled and we cannot checked or unchecked.

Consider making a method like:
private void ToggleCheckbox(AppiumWebElement checkbox, bool checked) { if(checkbox.Selected.Equals(checked)) return; checkbox.Selected = checked; }