{"record":{"id":"cd4054f7bc6dd215","repo":"dotnet/wpf","slug":"element-is-not-enabled-windowshyperlink","errorCode":null,"errorMessage":"Element is not enabled.","messagePattern":"Element is not enabled\\.","errorType":"exception","errorClass":"ElementNotEnabledException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/UIAutomation/UIAutomationClientSideProviders/MS/Internal/AutomationProxies/WindowsHyperlink.cs","lineNumber":424,"sourceCode":"            }\n        }\n\n        #endregion ProxySimple Interface\n\n        #region Invoke Pattern\n\n        // Same as clicking on an hyperlink\n        void IInvokeProvider.Invoke()\n        {\n            // Check that button can be clicked.\n            //\n            // This state could change anytime.\n            //\n\n            // Make sure that the control is enabled\n            if (!SafeNativeMethods.IsWindowEnabled(_hwnd))\n            {\n                throw new ElementNotEnabledException();\n            }\n\n            if (!SafeNativeMethods.IsWindowVisible(_hwnd))\n            {\n                throw new InvalidOperationException(SR.OperationCannotBePerformed);\n            }\n\n            //\n            // Get the bounding rect for the window.\n            //\n            NativeMethods.Win32Rect BoundingRect = NativeMethods.Win32Rect.Empty;\n            if (!Misc.GetWindowRect(_hwnd, ref BoundingRect))\n            {\n                return;\n            }\n\n            //\n            // All we really need here are the height and the width,","sourceCodeStart":406,"sourceCodeEnd":442,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/UIAutomation/UIAutomationClientSideProviders/MS/Internal/AutomationProxies/WindowsHyperlink.cs#L406-L442","documentation":"WindowsHyperlink's Invoke pattern checks IsWindowEnabled on the underlying hyperlink control before performing the click; a disabled control yields ElementNotEnabledException per the UIA Invoke pattern requirements.","triggerScenarios":"Invoking the hyperlink automation element while the control is disabled — Enabled=false set by app logic, disabled parent container, or disabled state pending a condition (e.g. terms not accepted).","commonSituations":"Automating dialogs where the hyperlink unlocks after validation; disabled links in installers/wizards; scripts racing ahead of the app enabling the control.","solutions":["Enable the control before invoking (fix app state that disables it).","Poll/wait for element.Current.IsEnabled == true (with timeout) before Invoke.","Catch ElementNotEnabledException and retry after the enabling condition is met.","If automating end-to-end, complete the prerequisite step (e.g. accept terms) that enables the link first."],"exampleFix":"// before\n((InvokePattern)element.GetCurrentPattern(InvokePattern.Pattern)).Invoke();\n// after\nvar sw = Stopwatch.StartNew();\nwhile (!element.Current.IsEnabled && sw.ElapsedMilliseconds < 5000) Thread.Sleep(100);\nif (element.Current.IsEnabled) ((InvokePattern)element.GetCurrentPattern(InvokePattern.Pattern)).Invoke();","handlingStrategy":"retry","validationCode":"bool enabled = element.Current.IsEnabled;\nif (!enabled) { /* wait or perform prerequisite action */ }","typeGuard":"static bool ReadyToInvoke(AutomationElement e) => e.Current.IsEnabled && !e.Current.IsOffscreen && e.TryGetCurrentPattern(InvokePattern.Pattern, out _);","tryCatchPattern":"try { invokePattern.Invoke(); }\ncatch (ElementNotEnabledException) { WaitForEnabled(element, TimeSpan.FromSeconds(5)); invokePattern.Invoke(); }","preventionTips":["Poll IsEnabled with a bounded timeout before invoking","Complete prerequisite steps (validation, terms acceptance) that gate the link","Catch ElementNotEnabledException explicitly rather than generic Exception","Keep wait timeouts finite and report the stuck state"],"tags":["uiautomation","invoke","element-disabled","hyperlink"],"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"}