{"record":{"id":"dc88a31ff9bb8358","repo":"dotnet/wpf","slug":"elementnotenabledexception-selectoritemautomationpeer","errorCode":null,"errorMessage":"ElementNotEnabledException","messagePattern":"ElementNotEnabledException","errorType":"exception","errorClass":"ElementNotEnabledException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Automation/Peers/SelectorItemAutomationPeer.cs","lineNumber":35,"sourceCode":"\n        ///\n        public override object GetPattern(PatternInterface patternInterface)\n        {\n            if(patternInterface == PatternInterface.SelectionItem)\n            {\n                return this;\n            }\n            return base.GetPattern(patternInterface);\n        }\n\n        /// <summary>\n        /// Sets the current element as the selection\n        /// This clears the selection from other elements in the container\n        /// </summary>\n        void ISelectionItemProvider.Select()\n        {\n            if(!IsEnabled())\n                throw new ElementNotEnabledException();\n\n            Selector parentSelector = (Selector)(ItemsControlAutomationPeer.Owner);\n            if (parentSelector == null)\n            {\n                throw new InvalidOperationException(SR.UIA_OperationCannotBePerformed);\n            }\n\n            parentSelector.SelectionChange.SelectJustThisItem(parentSelector.NewItemInfo(Item), true /* assumeInItemsCollection */);\n        }\n\n\n        /// <summary>\n        /// Adds current element to selection\n        /// </summary>\n        void ISelectionItemProvider.AddToSelection()\n        {\n            if(!IsEnabled())\n                throw new ElementNotEnabledException();","sourceCodeStart":17,"sourceCodeEnd":53,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Automation/Peers/SelectorItemAutomationPeer.cs#L17-L53","documentation":"ISelectionItemProvider.Select on SelectorItemAutomationPeer throws ElementNotEnabledException when IsEnabled() reports the underlying selector item is not enabled. UIA providers must refuse selection operations on disabled elements, mirroring how a user cannot click a disabled item. The exception is thrown before any selection logic runs.","triggerScenarios":"Calling Select (directly or via a UIA SelectionItemPattern) on an item whose control is disabled — e.g. a ListBoxItem or ComboBoxItem with IsEnabled=false, or an item in a disabled parent Selector.","commonSituations":"Automation tests driving selection while the item is temporarily disabled (data loading, validation pending); apps that disable items for unavailable options but whose test scripts still try to select them; regressions after a change that started disabling items.","solutions":["Check the item's IsEnabled (or the peer's IsEnabled) before calling Select and skip/abort if false","Enable the item first (set IsEnabled=true on the item or its container) if selection is legitimately expected","In UIA test code, re-query the element after enabling since cached state can be stale"],"exampleFix":"// before\nitemPeer.Select(); // throws if disabled\n// after\nif (itemPeer.IsEnabled())\n{\n    itemPeer.Select();\n}","handlingStrategy":"validation","validationCode":"if (!((ISelectionItemProvider)peer).IsEnabled())\n    return; // skip selection of disabled item\n((ISelectionItemProvider)peer).Select();","typeGuard":null,"tryCatchPattern":"try { peer.Select(); }\ncatch (ElementNotEnabledException) { /* item disabled; handle or skip */ }","preventionTips":["Check item IsEnabled before any SelectionItemPattern call","Keep automation element references fresh (re-query after UI state changes)","Align test data with business rules that disable certain items"],"tags":["wpf","ui-automation","element-not-enabled","selection"],"backgroundTag":"element-not-enabled","analyzedSha":"81131a70a4c573cd62748a5c36908fc4d662daa9","analyzedAt":"2026-09-14T10:12:48.479Z","contentChangedAt":"2026-09-14T10:12:48.479Z","schemaVersion":2},"datasetVersion":"2026-09-22T01:17:13.364Z"}