﻿namespace Winium.Desktop.Driver.CommandExecutors
{
    #region using

    using System.Windows.Automation;

    using Winium.Cruciatus.Extensions;
    using Winium.StoreApps.Common;

    #endregion

    internal class IsElementSelectedExecutor : CommandExecutorBase
    {
        #region Methods

        protected override string DoImpl()
        {
            var registeredKey = this.ExecutedCommand.Parameters["ID"].ToString();

            var element = this.Automator.Elements.GetRegisteredElement(registeredKey);

            var controlType = element.GetAutomationPropertyValue<ControlType>(AutomationElement.ControlTypeProperty);
            if (controlType.Equals(ControlType.CheckBox))
            {
                return this.JsonResponse(ResponseStatus.Success, element.ToCheckBox().IsToggleOn);
            }

            var property = SelectionItemPattern.IsSelectedProperty;
            var isSelected = element.GetAutomationPropertyValue<bool>(property);

            return this.JsonResponse(ResponseStatus.Success, isSelected);
        }

        #endregion
    }
}

﻿namespace Winium.Desktop.Driver.CommandExecutors
{
    #region using

    using System.Windows.Automation;

    using Winium.Cruciatus.Exceptions;
    using Winium.Cruciatus.Extensions;
    using Winium.StoreApps.Common;

    #endregion

    internal class IsElementSelectedExecutor : CommandExecutorBase
    {
        #region Methods

        protected override string DoImpl()
        {
            var registeredKey = this.ExecutedCommand.Parameters["ID"].ToString();

            var element = this.Automator.Elements.GetRegisteredElement(registeredKey);

            var isSelected = false;

            try
            {
                var isTogglePattrenAvailable =
                    element.GetAutomationPropertyValue<bool>(AutomationElement.IsTogglePatternAvailableProperty);

                if (isTogglePattrenAvailable)
                {
                    var toggleStateProperty = TogglePattern.ToggleStateProperty;
                    var toggleState = element.GetAutomationPropertyValue<ToggleState>(toggleStateProperty);

                    isSelected = toggleState == ToggleState.On;
                }
            }
            catch (CruciatusException)
            {
                var selectionItemProperty = SelectionItemPattern.IsSelectedProperty;
                isSelected = element.GetAutomationPropertyValue<bool>(selectionItemProperty);
            }

            return this.JsonResponse(ResponseStatus.Success, isSelected);
        }

        #endregion
    }
}

Check IsTogglePatternAvailable insted of using ControlType
Check IsTogglePatternAvailable insted of using ControlType
