{"record":{"id":"5ad1c84da6cfc432","repo":"dotnet/wpf","slug":"elementnotenabledexception-hyperlinkautomationpeer","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/HyperlinkAutomationPeer.cs","lineNumber":84,"sourceCode":"            return \"Hyperlink\";\n        }\n\n        /// <summary>\n        /// <see cref=\"AutomationPeer.IsControlElementCore\"/>\n        /// </summary>\n        protected override bool IsControlElementCore()\n        {\n            // We only want this peer to show up in the Control view if it is visible\n            // For compat we allow falling back to legacy behavior (returning true always)\n            // based on AppContext flags, IncludeInvisibleElementsInControlView evaluates them.\n            return IncludeInvisibleElementsInControlView || IsTextViewVisible == true;\n        }\n\n        //Invoke Pattern implementation\n        void IInvokeProvider.Invoke()\n        {\n            if (!IsEnabled())\n                throw new ElementNotEnabledException();\n\n            Hyperlink owner = (Hyperlink)Owner;\n            owner.DoClick();\n        }\n    }\n}\n","sourceCodeStart":66,"sourceCodeEnd":91,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Automation/Peers/HyperlinkAutomationPeer.cs#L66-L91","documentation":"HyperlinkAutomationPeer implements IInvokeProvider.Invoke and throws ElementNotEnabledException when IsEnabled() returns false, i.e. the Hyperlink (or an ancestor such as a disabled TextBlock/TextBox) is disabled. Invoke on a disabled hyperlink is rejected with the UIA ELEMENTNOTENABLED error.","triggerScenarios":"Calling IInvokeProvider.Invoke() (or UIA Invoke pattern) on a Hyperlink automation peer while the hyperlink or its containing control is disabled (IsEnabled == false).","commonSituations":"Automated tests clicking links inside a disabled RichTextBox/TextBox or TextBlock under a disabled parent; UIA scripts invoking links before a window finishes loading/enabling; apps that disable hyperlinks pending validation.","solutions":["Enable the Hyperlink and its parent chain (control.IsEnabled = true) before invoking.","Wait for the element to become enabled in UIA clients (check IsEnabled property / WaitForInputIdle) before Invoke.","Catch ElementNotEnabledException and retry after the UI reaches the enabled state."],"exampleFix":"// before\ninvokePattern.Invoke(); // may throw when hyperlink disabled\n// after\nif (hyperlink.IsEnabled)\n{\n    invokePattern.Invoke();\n}","handlingStrategy":"validation","validationCode":"if (!hyperlink.IsEnabled) return; // or wait until enabled","typeGuard":"bool Invokable(Hyperlink h) => h is { IsEnabled: true };","tryCatchPattern":"try { invokePattern.Invoke(); } catch (ElementNotEnabledException) { /* wait/retry after enabling */ }","preventionTips":["Check IsEnabled on the hyperlink and its ancestors before Invoke.","In UIA clients, poll or wait on the IsEnabled property.","Avoid invoking links in disabled containers (disabled RichTextBox/TextBox)."],"tags":["wpf","ui-automation","element-not-enabled"],"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-22T01:17:13.364Z"}