ValuePattern's SetValue doesnot work for chorme borwser's contorl like address edit
-
Monday, April 30, 2012 4:32 AM
Hi, 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.AutomationElement.SetFocus()
在 BrowserControl.Browser.Browser.Goto(String url) 位置 C:\Users\darren\documents\visual studio 2010\Projects\BrowserControl\BrowserControl\Browser\Browser.cs:行号 108
在 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 contorl
Now that choose the destination, so we should keep on
All Replies
-
Monday, April 30, 2012 4:34 AMSorry, the above exception is raised when I called SetFocus for the element, infact when I call SetValue for it, a same exception also be thrown.
Now that choose the destination, so we should keep on
-
Monday, April 30, 2012 7:19 AM
I found that I can send message to the address edit via SendKeys, but as I cannot set focus for the control, so I still can not workaround it. is there any ways....
System.Windows.Forms.SendKeys.SendWait(@"http://www.tom.com"); // Move to start of control
System.Windows.Forms.SendKeys.SendWait("{enter}"); // Move to start of controlNow that choose the destination, so we should keep on
-
Tuesday, May 01, 2012 1:03 AM
Hi,
It looks like you're using the managed UI Automation (UIA) API that's included in the .NET Framework. I'm only familiar with the native-code version of the UIA API that's including with Windows, but I think in this case the following would apply to clients of both APIs.
If I want to programmatically click a button to navigate in a browser, I'd first check if the UI I'm interested in supports the Invoke Pattern. The Invoke Pattern allows you to programmatically invoke an element, and that normally triggers the same action that would happen if you click on it with a mouse. As a test, I pointed the Inspect tool that’s available in the Window SDK to the Back button in Internet Explorer. Inspect showed me that the Invoke Pattern is supported, and so I can programmatically invoke the button from Inspect by going to Inspect's Action menu and selecting "Invoke.Invoke". (That means Inspect calls the Invoke() method on the button's UI through the Invoke Pattern.) The image below shows Inspect interacting with the back button in IE.
So you may want to use Inspect to see if the UI you’re interested in supports the Invoke Pattern, and if it does, interact with the UI through that pattern.
Thanks,
Guy
- Marked As Answer by Michael BernsteinMicrosoft Employee, Owner Friday, June 15, 2012 3:44 PM


