//////////////////////////////////////////////////////////////////////////////////////////////////////////////
        //
        // InvokeLinkInternal()
        //
        // Invoke a hyperlink in the browser window.
        //
        // Runs on the background thread.
        //
        //////////////////////////////////////////////////////////////////////////////////////////////////////////////
        private void InvokeLinkInternal(IUIAutomationElement elementLink, bool fUseCache)
        {
            if (elementLink != null)
            {
                IUIAutomationInvokePattern pattern = null;

                int iPatternId = _patternIdInvoke;

                // Will we be calling the Invoke() method through the Invoke pattern.
                // So first get the pattern for the hyperlink element.
                if (fUseCache)
                {
                    // This does not result in a cross-proc call here, and should not fail.
                    pattern = (IUIAutomationInvokePattern)elementLink.GetCachedPattern(iPatternId);
                }
                else
                {
                    // This will fail if the element no longer exists.
                    try
                    {
                        pattern = (IUIAutomationInvokePattern)elementLink.GetCurrentPattern(iPatternId);
                    }
                    catch
                    {
                        // If an exception is throw trying to access the element, do nothing. This will
                        // occur if the element no longer exists, (eg the browser window has been closed.)
                    }
                }

                if (pattern != null)
                {
                    pattern.Invoke();
                }
            }
        }
예제 #2
0
 public static IUIAutomationElement xtInvoke(this IUIAutomationElement element)
 {
     _InvokePattern = (IUIAutomationInvokePattern)element.GetCurrentPattern(UIA_PatternIds.UIA_InvokePatternId);
     try { _InvokePattern.Invoke(); } catch (COMException com) { }
     return(element);
 }
 public override void Invoke()
 {
     _invokePattern.Invoke();
 }