/// <summary> /// 获取复选框元素选择状态 /// </summary> /// <param name="element">复选框元素</param> /// <returns>选择状态</returns> public static ECheckBoxStatus CF_GetCheckBoxStatu(AutomationElement element) { ECheckBoxStatus checkBoxStatus = ECheckBoxStatus.Error; if (element != null && element.Current.ControlType == ControlType.CheckBox) { try { if (element.TryGetCurrentPattern(TogglePattern.Pattern, out object pattern)) { TogglePattern togglePattern = pattern as TogglePattern; ToggleState toggleState = togglePattern.Current.ToggleState; checkBoxStatus = toggleState == ToggleState.On ? ECheckBoxStatus.On : toggleState == ToggleState.Off ? ECheckBoxStatus.Off : ECheckBoxStatus.Indeterminate; } } catch { } } return(checkBoxStatus); }
/// <summary> /// 复选框状态是否获取错误 /// </summary> /// <param name="checkBoxStatus">复选框状态</param> /// <returns>获取结果</returns> public static bool CF_IsError(this ECheckBoxStatus checkBoxStatus) { return(checkBoxStatus == ECheckBoxStatus.Error); }