{"record":{"id":"558c4c5e611f4eb2","repo":"dotnet/wpf","slug":"uia-e-elementnotenabled","errorCode":"UIA_E_ELEMENTNOTENABLED","errorMessage":"description (from UiaGetErrorDescription or SR.UnknownCoreAPIError)","messagePattern":"description \\(from UiaGetErrorDescription or SR\\.UnknownCoreAPIError\\)","errorType":"exception","errorClass":"ElementNotEnabledException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/UIAutomation/UIAutomationClient/MS/Internal/Automation/UiaCoreApi.cs","lineNumber":1188,"sourceCode":"            {\n                return;\n            }\n\n            // Handle these UIA exceptions specially - COM Interop\n            // maps others (eg. InvalidArgument), but not these:\n            if (hr == UIA_E_ELEMENTNOTENABLED\n            || hr == UIA_E_ELEMENTNOTAVAILABLE\n            || hr == UIA_E_NOCLICKABLEPOINT\n            || hr == UIA_E_PROXYASSEMBLYNOTLOADED)\n            {\n                string description;\n                if (!UiaGetErrorDescription(out description))\n                    description = SR.UnknownCoreAPIError;\n\n                switch (hr)\n                {\n                    case UIA_E_ELEMENTNOTENABLED:\n                        throw new ElementNotEnabledException(description);\n\n                    case UIA_E_ELEMENTNOTAVAILABLE:\n                        throw new ElementNotAvailableException(description);\n\n                    case UIA_E_NOCLICKABLEPOINT:\n                        throw new NoClickablePointException(description);\n\n                    case UIA_E_PROXYASSEMBLYNOTLOADED:\n                        throw new ProxyAssemblyNotLoadedException(description);\n                }\n            }\n\n            // Not a UIA-specific exception - let COM Interop handle the rest.\n            // (Marshal.ThrowExceptionForHR automatically calls GetErrorInfo to fill in the description\n            // field - UIA sets the error info itself, so it will get propogated here.)\n            Marshal.ThrowExceptionForHR(hr);\n        }\n","sourceCodeStart":1170,"sourceCodeEnd":1206,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/UIAutomation/UIAutomationClient/MS/Internal/Automation/UiaCoreApi.cs#L1170-L1206","documentation":"UiaCoreApi translates HRESULTs returned by the native UI Automation Core into the corresponding WPF UIAutomation client exceptions. When the core returns UIA_E_ELEMENTNOTENABLED, the WrapNativeExceptionIfRequired path throws ElementNotEnabledException with a description obtained via UiaGetErrorDescription (or a fallback 'unknown error' string). It means the automation operation targeted a control that exists but is currently disabled (not interactive).","triggerScenarios":"Calling any UIA client operation (e.g. AutomationElement pattern invocation, InvokePattern.Invoke) that performs a native UIA call which fails with HRESULT UIA_E_ELEMENTNOTENABLED (0x80040200) on a disabled element.","commonSituations":"Automating a button/menu item that is disabled until form fields are filled; clicking controls in a wizard step that has not been enabled yet; UI tests racing against the app enabling controls after async validation.","solutions":["Before interacting, check the IsEnabled property of the AutomationElement and wait until it is true (poll or subscribe to the IsEnabled property-changed event)","Fix the automation flow to enable the control first (fill required fields, complete prerequisite steps) in the app under test","Catch ElementNotEnabledException and retry after a delay if the UI may enable the element shortly","If the element should be enabled but is not, investigate the target application's enable/disable logic"],"exampleFix":"// before\ninvokePattern.Invoke();\n// after\nif (button.Current.IsEnabled)\n{\n    invokePattern.Invoke();\n}","handlingStrategy":"validation","validationCode":"if (!element.Current.IsEnabled)\n{\n    // wait/poll until enabled, or fail fast with a clear message\n    WaitForEnabled(element, timeout: TimeSpan.FromSeconds(5));\n}","typeGuard":"static bool IsInteractive(AutomationElement e) => e.Current.IsEnabled && !e.Current.IsOffscreen;","tryCatchPattern":"try { invokePattern.Invoke(); }\ncatch (ElementNotEnabledException) { RetryAfterDelayOrAbort(); }","preventionTips":["Check IsEnabled before every interaction","Subscribe to IsEnabled property-changed events instead of polling","Build waits into UI test helpers for asynchronously-enabled controls"],"tags":["uiautomation","wpf","disabled-element"],"backgroundTag":"invalid-state-transition","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"}