0

I am trying to use UIA to control browsers (ie, chrome, firefox) operations like nativate, go back, go forward and so on for some testing necessary. I tried to wrote some demo code, but met some problems. I got the AutomationElement for address edit for Chrome, and try to set url for it with ValuePattern, but I got exception below:

在 System.Runtime.InteropServices.Marshal.ThrowExceptionForHRInternal(Int32 errorCode, IntPtr errorInfo)
在 MS.Internal.Automation.UiaCoreApi.CheckError(Int32 hr)
在 System.Windows.Automation.ValuePattern.SetValue(String value)
在 BrowserControl.Browser.Browser.Goto(String url) 位置 C:\Users\darren\documents\visual studio 2010\Projects\BrowserControl\BrowserControl\Browser\Browser.cs:行号 109
在 BrowserControl.Program.Main(String[] args) 位置 C:\Users\darren\documents\visual studio 2010\Projects\BrowserControl\BrowserControl\Program.cs:行号 17
在 System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
在 System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
在 Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
在 System.Threading.ThreadHelper.ThreadStart_Context(Object state)
在 System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean ignoreSyncCtx)
在 System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
在 System.Threading.ThreadHelper.ThreadStart()

And I found that SetFoucus method also will got the same exception. I tried to use win32 method to send message to it, found that the element.Current.NativeWindowHandle is null. but I can see the current value from ValuePattern's current property. Just for a address that the UIA cannot find the chrome's control firstly until I called the below method ()UiaRegisterProviderCallback(IntPtr.Zero);

So, not sure what's reason for it, and is there anyway to set value for chrome's control

4

1 回答 1

0

如果不深入研究 Chrome 源代码,我无法确定这一点,但我的猜测是 Chrome 中的地址栏实际上是一个自定义控件,这就是为什么你没有看到它像标准文本框那样完全符合 ValuePattern/编辑框。我在其他地方看到过类似的事情,我通常最终会使用SendKeys做某种解决方法。

于 2012-07-30T02:23:39.223 回答