Null being returned Intermittently

Mar 26, 2012 at 2:22 AM

Hi

I discovered white a few days ago from a codeproject article

http://www.codeproject.com/Articles/289028/White-An-UI-Automation-tool-for-windows-applicatio

Below is the relevant code I'm using to get a comboBox and a button. 50% of the time the code returns null for either the comboBox or the calculateButton or both. Other times its fine. Any ideas?

I'm using Win 7, VS2010 with target framework of .Net 4, downloaded the github sources and built the White.Core.dll.

Thanks a lot

John

......

    private static White.Core.Application _application;
    private static White.Core.UIItems.WindowItems.Window _mainWindow;

.....
.....

        string executableSourceFile = @"C:\Windows\system32\calc.exe";
        ProcessStartInfo psi = new ProcessStartInfo(executableSourceFile);
        _application = White.Core.Application.AttachOrLaunch(psi);
        _mainWindow = _application.GetWindow(SearchCriteria.ByText("Calculator"), InitializeOption.NoCache);

.....
.....

      // open the date calculations panel first, then


      ComboBox comboBox =  _mainWindow.Get<ComboBox>(SearchCriteria.ByAutomationId("4003"));
      Button calculateButton = _mainWindow.Get<Button>(SearchCriteria.ByAutomationId("4009"));

Mar 29, 2012 at 3:48 PM
Edited Mar 29, 2012 at 3:49 PM

Almost all controls in Calculator are children of "pane", not the main window.

Try

Panel pane = _mainWindow.Get<Panel>(SearchCriteria.All);

ComboBox comboBox = pane.Get<ComboBox>(SearchCriteria.ByAutomationId("4003"));
            Panel pane = window.Get<Panel>(SearchCriteria.All);
Mar 30, 2012 at 4:15 AM

Michael

Thanks for the guidance. Didn't quite do it that way, but all is working perfectly.

John

 

Mar 26, 2013 at 3:36 AM
I have the same problem. John, please tell me your solution. I tried everything and still nothing.
Coordinator
Mar 26, 2013 at 3:39 AM
This project has moved to https://github.com/TestStack/White and there is a new NuGet package 'TestStack.White'

White no longer will return null's, instead it will throw, giving you an error message about why it could not find the element. Please swap over to TestStack.White as the old versions are no longer supported
Mar 26, 2013 at 3:42 AM
Edited Mar 26, 2013 at 3:43 AM
I was unclear. I have the same problem in a sense I can not refer to this Combobox. But yes, the exception is thrown. So a big part of this http://www.codeproject.com/Articles/289028/White-An-UI-Automation-tool-for-windows-applicatio example does not work.

I have the latest version.
Coordinator
Mar 26, 2013 at 4:25 AM
I just grabbed the example code, and installed TestStack.White, it seems to work fine for me.

I will add a few more automated tests around Win32 because it is a gap at the moment, but I need more information to sort it out.
Mar 26, 2013 at 5:12 AM
Edited Mar 26, 2013 at 5:13 AM
Hm. I'll be right back.
Mar 26, 2013 at 5:21 AM
Edited Mar 26, 2013 at 5:27 AM
Yes, you are right. I was transforming that console application to WPF form and forgot to set focus on the Calculator window. By the way, how to do this in the most efficient way? I just did
        var help = _mainWindow.Get<White.Core.UIItems.MenuItems.Menu>(SearchCriteria.ByText("Help"));
        help.Click();
        help.Click();
?

I searched API at http://www.symbolsource.org/Public/Metadata/Default/Project/White/0.20/Release/All/White.Core/White.Core/UIItems/ListBoxItems/ComboBox.cs
but with no success.

A bit noobish questions... =)
Coordinator
Mar 26, 2013 at 5:53 AM
Edited Mar 26, 2013 at 5:54 AM
I just added a test which is the same as the example project at https://github.com/TestStack/White/commit/51aaa5dacdc30dfec18c060b71aefdf6199801dd

If that test fails for you, please give me the exception which is thrown.
Coordinator
Mar 26, 2013 at 5:56 AM
The most efficient way is using Automation ID's in WPF.

Please have a look at the same project in the White github repo