问题描述
您好,
我目前正在使用UIAutomation API来处理Javascript对话框。 在大多数情况下,这已经很有效,但我经常得到这个随机异常,我不知道如何解决/修复它。
例外:热键已经注册
类型:System.ComponentModel.Win32Exception
Stack: 在MS.Internal.AutomationProxies.Misc.ThrowWin32ExceptionsIfError(Int32 errorCode)
在MS.Internal.AutomationProxies.Misc.SetFocus(IntPtr hwnd)
在MS.Internal.AutomationProxies.WindowsButton.Invoke()
在MS.Internal.AutomationProxies.WindowsButton.System.Windows.Automation.Provider.IInvokeProvider.Invoke()
在System.Runtime.InteropServices.Marshal.ThrowExceptionForHRInternal(Int32 errorCode,IntPtr errorInfo)
在System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(Int32 errorCode)
在MS.Internal.Automation.UiaCoreApi.CheckError(Int32 hr)
在System.Windows.Automation.InvokePattern.Invoke()
这是我用来处理对话框的代码。
var okButton = window.FindFirst(TreeScope.Descendants, new PropertyCondition(AutomationElement.AutomationIdProperty," 1" ));
var invokePattern = okButton.GetCurrentPattern(InvokePattern.Pattern) as InvokePattern;
invokePattern.Invoke();
Hello,
I am currently using the UIAutomation API to handle Javascript dialogs. For the most part this has worked great but every so often I get this random Exception and I'm not sure how to work around/fix it.
Exception:Hot key is already registered
Type:System.ComponentModel.Win32Exception
Stack: at MS.Internal.AutomationProxies.Misc.ThrowWin32ExceptionsIfError(Int32 errorCode)
at MS.Internal.AutomationProxies.Misc.SetFocus(IntPtr hwnd)
at MS.Internal.AutomationProxies.WindowsButton.Invoke()
at MS.Internal.AutomationProxies.WindowsButton.System.Windows.Automation.Provider.IInvokeProvider.Invoke()
at System.Runtime.InteropServices.Marshal.ThrowExceptionForHRInternal(Int32 errorCode, IntPtr errorInfo)
at System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(Int32 errorCode)
at MS.Internal.Automation.UiaCoreApi.CheckError(Int32 hr)
at System.Windows.Automation.InvokePattern.Invoke()
This is the code that I am using to handle the dialog.
var okButton = window.FindFirst(TreeScope.Descendants, new PropertyCondition(AutomationElement.AutomationIdProperty, "1")); var invokePattern = okButton.GetCurrentPattern(InvokePattern.Pattern) as InvokePattern; invokePattern.Invoke();
这篇关于InvokePattern.Invoke抛出Win32Exception“热键已经注册”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!