Windows UI Automation

I was testing the follow sample code and somehow whenever I tried running it, I will have an error shown below. However, the calc.exe process was executed successfull, so how is it possible that the handle be null or zero? I hope you understand what I am trying to put across. Thanks! The code sample is from http://www.mathpirate.net/log/tag/system-windows-automation/

An unhandled exception of type 'System.ArgumentException' occurred in UIAutomationClient.dll Additional information: hwnd cannot be IntPtr.Zero or null.

//Launches the Windows Calculator and gets the Main Window's Handle. Process calculatorProcess = Process.Start("calc.exe"); calculatorProcess.WaitForInputIdle(); IntPtr calculatorWindowHandle = calculatorProcess.MainWindowHandle; //Here I use a window handle to get an AutomationElement for a specific window. AutomationElement calculatorElement = AutomationElement.FromHandle(calculatorWindowHandle); if(calculatorElement == null) { throw new Exception("Uh-oh, couldn't find the calculator..."); } //Walks some of the more interesting properties on the AutomationElement. Console.WriteLine("--------Element"); Console.WriteLine("AutomationId: {0}", calculatorElement.Current.AutomationId); Console.WriteLine("Name: {0}", calculatorElement.Current.Name); Console.WriteLine("ClassName: {0}", calculatorElement.Current.ClassName); Console.WriteLine("ControlType: {0}", calculatorElement.Current.ControlType.ProgrammaticName); Console.WriteLine("IsEnabled: {0}", calculatorElement.Current.IsEnabled); Console.WriteLine("IsOffscreen: {0}", calculatorElement.Current.IsOffscreen); Console.WriteLine("ProcessId: {0}", calculatorElement.Current.ProcessId); //Commented out because it requires another library reference. However, it's useful to see that this exists. //Console.WriteLine("BoundingRectangle: {0}", calculatorElement.Current.BoundingRectangle); Console.WriteLine("Supported Patterns:"); foreach (AutomationPattern supportedPattern in calculatorElement.GetSupportedPatterns()) { Console.WriteLine("\t{0}", supportedPattern.ProgrammaticName); }

--------------Solutions-------------

You're misunderstanding WaitForInputIdle (Which is a HORRENDOUSLY bad name for what that function currently does). You're asking for the address of the main window before a main window has even been created. As a result you end up passing an invalid window handle to your other functions.

EDIT: I would strongly recommend use of a UI Automation library such as white if you're going to be doing serious work with it.

Category:c# Time:2010-07-02 Views:1

Related post

  • How Do I 'Restore' MS Word's Document Window Using Automation 2009-06-11

    I would like to be able to 'restore' MS Word's document window using Automation. I already have the application object and I have tried calling App.Activate. Activate will bring the window to the top of the Window stack but not if Word is minimized.

  • Windows GUI Automation 2010-06-01

    I am planning to automate some of the functionality of the GUI developed in Microsoft Visual C#. I am new to Automation with GUI. Would be glad if you share your experience regarding GUI Automation and some of the tools available for the automation.

  • Windows phone Automation Test Soluction 2012-01-13

    well. For a single module in terms of regression testing In order to improve the efficiency of the introduction of the concept of automated testing. Unfortunately, there is no any application for Windows phone Application of automated testing tools h

  • Windows UI Automation API 2012-02-07

    I have been trying to figure this out for a while so any help would be greatly appreciated. I am using UI Automation in my client to monitor and report on user selection within another application. I got the code working perfectly on Server 2003. On

  • I'm on the page for windows-update-issues/en-us, but the Windows Update Automated Troubleshooter will not run??? 2012-08-03

    Loaded Windows XP, service pack 2, to enable me to upgrade to IE 8...it seemed to load okay, but the Microsoft web site told me to start the new explorer (8), then go to the Tools menu, and select Windows Update to complete the installation, but it a

  • Windows 7 - Automated update stuck all night at 3 of 13 2013-05-26

    Windows 7 - Automated update stuck all night at 3 of 13. Do I wait? Is it supposed to take 10 hours to run that step? Is there a problem with the update? --------------Solutions------------- Hi, Cancel the windows that you are at, restart your comput

  • Windows Update Automated Troubleshooter fails to run 2013-11-07

    The Windows Update Automated Troubleshooter ( http://support.microsoft.com/gp/windows-update-issues/en-us ) does not work. When I click on "Run now," it tries to open a file named "WindowsUpdateDiagnostic.diagcab," but "diagcab" is not an extension r

  • BSOD installing Windows Update Automated Troubleshooter 2013-12-11

    I have a nvidea update that would not install properly after multiple trys. I had to restore to an earlier point to fix and boot. I then tried installing the Windows Update Automated Troubleshooter. It crashed on installation and now I get BSOD on bo

  • when i run the Windows Update Automated Troubleshooter , getting error potential windows update database error detected 0X80070005 2014-08-15

    i used Windows Update Automated Troubleshooter from http://support.microsoft.com/gp/windows-update-issues and it is showing errors error potential windows update database error detected 0X80070005. please help in solving this --------------Solutions-

  • Running Windows UI automation tasks which are stored in a database 2010-09-22

    I am storing a list of links to resources such as documents to be opened by Windows applications as well as web pages in a database and need to know how to open them in Windows. For some webpages it will be achieved by passing parameters to a web bro

  • WIndows GUI automation on minimized window 2010-10-28

    As a disclaimer I am not at all familiar with Win32 development. I was wondering if there was any way to automate control input to a GUI application if that application is minimized. Most automation tools I have seen specifically use coordinate offse

  • Windows 7: Automated folder action on copy 2011-05-08

    I'm running Windows 7 pro. I have a folder called "Media" in the root of my C:\ What I want to do is that when I copy some form of video media, ex .mov file to that folder, that it would detect the copy, once completed, fire handbrake or FFMPEG via t

  • Read information from CMD, browser using windows UI automation 2011-10-26

    I can understand how UI automation can help retrieve information from text boxes within windows forms applications. How can I retrieve information however from command prompt tools and web browsers? I have a telnet session that I would like to read d

  • Which Python extension for Windows GUI automation offers the most flexibility for tackling poorly designed UIs? 2012-01-06

    I have a horribly complicated (and very poorly designed) autodialer application I need to automate to make it possible for some less technical users to contact customers. I would like to try using Python to accomplish this, and was wondering what exp

  • Windows update, dual booting with Windows 7 - automation? 2014-08-24

    The most annoying feature of dual booting, or indeed, running a different Windows version in a VM, is that Windows updates have to be done for each OS, if I want to keep both OS versions current and secure. On the second OS, which may be used just oc

  • Windows UI Automation not showing all child elements? 2011-08-30

    I have a TreeView control on my form, and I'm recursively going through the elements of another window starting with the window itself. I'm using this to find the elements: getRecursiveElements(AutomationElement parent) { children = parent.FindAll(Tr

  • Why to use ironruby for Windows UI Automation 2012-03-15

    I want to automate my test of a windows application (WPF) and I found some articles about doing that with ironruby, however which is the killer reason for writing it with ruby instead of c#. --------------Solutions------------- The killer reason(s) c

  • Windows Update Automated version is offering Office 2010 SP2 32 Bit on my 64 Bit Windows 7 PC. 2012-04-03

    This seems to be an error - The auto update does not seem to have detected my PC is a 64 bit machine. But the SP updates are generally quite critical and not the type to get wrong. But then again, I seem to recall there may have been an issue that Of

  • i have windows vista in my pc and my windows 7 automated r1 set up wont work 2012-04-10

    the page will come up on screen it says Install Windows 7tm Exstreme Adition r1 when i click on it just dosent do anything --------------Solutions------------- Hi, · When exactly do you receive the message that you have mentioned in the question? · W

Copyright (C) pcaskme.com, All Rights Reserved.

processed in 0.741 (s). 13 q(s)