{"record":{"id":"6c59a5946f34360e","repo":"dotnet/wpf","slug":"new-elementnotenabledexception","errorCode":null,"errorMessage":"new ElementNotEnabledException()","messagePattern":"new ElementNotEnabledException\\(\\)","errorType":"exception","errorClass":"ElementNotEnabledException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/UIAutomation/UIAutomationClient/System/Windows/Automation/RangeValuePattern.cs","lineNumber":91,"sourceCode":"\n        //------------------------------------------------------\n        //\n        //  Public Methods\n        //\n        //------------------------------------------------------\n \n        #region Public Methods\n        /// <summary>\n        /// Request to set the value that this UI element is representing\n        /// </summary>\n        /// <param name=\"value\">Value to set the UI to, as a double</param>\n        public void SetValue(double value)\n        {\n            // Test the Enabled state prior to the more general Read-Only state.            \n            object enabled = _el.GetCurrentPropertyValue(AutomationElementIdentifiers.IsEnabledProperty);\n            if (enabled is bool && !(bool)enabled)\n            {\n                throw new ElementNotEnabledException();\n            }\n\n            // Test the Read-Only state after the more specific Enabled state.\n            object readOnly = _el.GetCurrentPropertyValue(IsReadOnlyProperty);\n            if (readOnly is bool && (bool)readOnly)\n            {\n                throw new InvalidOperationException(SR.ValueReadonly);\n            }\n            UiaCoreApi.RangeValuePattern_SetValue(_hPattern, value);\n        }\n\n        #endregion Public Methods\n\n\n        //------------------------------------------------------\n        //\n        //  Public Properties\n        //","sourceCodeStart":73,"sourceCodeEnd":109,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/UIAutomation/UIAutomationClient/System/Windows/Automation/RangeValuePattern.cs#L73-L109","documentation":"RangeValuePattern.SetValue first checks the element's IsEnabled property; if the element reports disabled, it throws ElementNotEnabledException. The pattern deliberately tests Enabled before the more general read-only check so callers get the most specific error.","triggerScenarios":"Calling SetValue on a RangeValuePattern whose automation element is disabled (IsEnabledProperty false): e.g. a slider/spinner disabled in the UI, a window disabled/modally blocked, or an invalid-state control.","commonSituations":"Automating UI where the target control is disabled until a preceding step completes; test automation racing with app initialization; interacting with controls in disabled dialogs.","solutions":["Before SetValue, read AutomationElement.IsEnabledProperty (or TryGetCurrentPropertyValue) and skip/enable the control first","Wait for the element to become enabled (poll or automation event on IsEnabledProperty/property-changed events)","Catch ElementNotEnabledException around SetValue and surface a clear failure to the test/user","Re-acquire the pattern/element; stale cached state can report incorrect enabled values"],"exampleFix":"// before\nrangePattern.SetValue(10); // ElementNotEnabledException if disabled\n// after\nif (element.TryGetCurrentPropertyValue(AutomationElement.IsEnabledProperty, out var enabled) && (bool)enabled)\n{\n    rangePattern.SetValue(10);\n}","handlingStrategy":"try-catch","validationCode":"bool isEnabled = element.TryGetCurrentPropertyValue(AutomationElement.IsEnabledProperty, out var en) && en is bool b && b;\nif (!isEnabled) return; // skip or wait until enabled","typeGuard":"bool IsEnabled(AutomationElement e) => e.TryGetCurrentPropertyValue(AutomationElement.IsEnabledProperty, out var v) && v is bool b && b;","tryCatchPattern":"try { rangePattern.SetValue(value); } catch (ElementNotEnabledException) { /* wait for enablement or abort step */ }","preventionTips":["Check IsEnabledProperty before SetValue","Subscribe to property-changed events to wait for enablement","Re-acquire patterns after UI state changes","Handle disabled controls explicitly in test automation flows"],"tags":["uiautomation","rangevalue-pattern","element-not-enabled","disabled-control"],"backgroundTag":"unsupported-operation","analyzedSha":"81131a70a4c573cd62748a5c36908fc4d662daa9","analyzedAt":"2026-09-14T10:12:48.479Z","contentChangedAt":"2026-09-14T10:12:48.479Z","schemaVersion":2},"datasetVersion":"2026-09-21T21:30:21.729Z"}