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

iandotkelly
  • 9,024
  • 8
  • 48
  • 67

2 Answers2

0

I can't be certain of this without digging into the Chrome source, but my guess would be that the address bar in Chrome is actually a custom control and that's why you aren't seeing it conform perfectly to the ValuePattern like a standard textbox/editbox. I've seen things like this pop up elsewhere, and I usually end up doing some sort of workaround using SendKeys.

Chaser324
  • 478
  • 2
  • 12
0

I encountered this issue too and it sometimes occur and sometimes not despite using the exact same code, which confused me greatly. Then I discovered that Chrome doesn't always turn on accessibility until it detects assistive software for performance reasons. Adding the --force-renderer-accessibility flag solved the issue.

skygate
  • 363
  • 2
  • 11