Exceptions when trying to get a Window from the Desktop

Apr 15, 2008 at 12:08 PM
Hi,

We're trying to get a Window object from the Desktop using the code:

Window window = White.Desktop.Instance.Get<Window>(SearchCriteria.ByText(windowTitle));

But when we try and run the code we get a NullReferenceException back, to be precise, we get:

System.NullReferenceException occurred
Message="Object reference not set to an instance of an object."
Source="Core"
StackTrace:
at Core.Mappings.ControlDictionary.GetControlType(Type type) in c:\cruisecontrolrb\projects\white\work\Core\Mappings\ControlDictionary.cs:line 100

We've also tried the line:

Window window = (Window)White.Desktop.Instance.Get(SearchCriteria.ByText(windowTitle));

But this also gives an exception, but in this case an invalid cast exception.

Should either of the two ways we've tried to get Window objects from the desktop work? If not, how do we get Window objects from the desktop? Or is getting Window objects not possible using the .Get method any anything other than an application object?

Thanks,

James.

Coordinator
Apr 15, 2008 at 2:30 PM
Please use Desktop.Instance.Windows() to get all the windows and then you can find the window which you are interested in.
I think I should make the error more clearer because Get<Window> would not work (or there should be a compile time error). Get is supposed to provide you only PrimaryUIItems, window is not a primary item.
Sorry about the lack of clarity. This should get fixed in next release.
Apr 16, 2008 at 3:01 PM


viveksingh wrote:
Please use Desktop.Instance.Windows() to get all the windows and then you can find the window which you are interested in.
I think I should make the error more clearer because Get<Window> would not work (or there should be a compile time error). Get is supposed to provide you only PrimaryUIItems, window is not a primary item.
Sorry about the lack of clarity. This should get fixed in next release.


Thats makes sense, we'll use the Desktop.Instance.Windows() approach.

Can I ask, is the TitleBar object not a primaryUIItem also?

Thanks,

James.
Coordinator
Apr 16, 2008 at 6:11 PM
Since there is only one titlebar on a window, this is available from window object. You dont need to worry about how to find it.
I understand that these need to be documented clearly.