public static IUIAutomationElement xtToggleCheckBox(this IUIAutomationElement element, bool Check) { if (element.CurrentIsEnabled == 1) { _TogglePattern = (IUIAutomationTogglePattern)element.GetCurrentPattern(UIA_PatternIds.UIA_TogglePatternId); bool IsSelected = _TogglePattern.CurrentToggleState == ToggleState.ToggleState_On; if (Check != IsSelected) { try { _TogglePattern.Toggle(); } catch (COMException e) { } } Thread.Sleep(10); } _TogglePattern = (IUIAutomationTogglePattern)element.GetCurrentPattern(UIA_PatternIds.UIA_TogglePatternId); if (Check != (_TogglePattern.CurrentToggleState == ToggleState.ToggleState_On)) { throw new Exception("Checkbox was not properly Toggled!!!"); } return(element); }
/// <summary> /// Toggle the element. /// </summary> public void Toggle() { _pattern.Toggle(); }
public override void Invoke() { _togglePattern.Toggle(); }