This project is read-only.

File Open Dialog Box

Aug 17, 2010 at 11:53 AM
Edited Aug 17, 2010 at 11:56 AM


This is my problem. I have an application where it opens a file open dialog box and I'm trying to enter in the file path and file name into the "File name:" combo box section.

The application loads with a form where you log in. This opens another form where there are a number of buttons. Choosing one of these buttons opens another form. It is in this form that there is a button to select a file. At this stage there's 3 forms opened. This will open the standard file open dialog box. I can't seem to get a handle on this file open dialog box.

Here's the code I'm using.

Window LoginForm = application.GetWindow("LoginForm");
LoginForm.Get<Button>("btnSelectFiles").Click(); // This is from the 3rd form that is opened 

For some reason, I can access all buttons from the other forms using the LoginForm variable.
I've tried the following.

Window FileOpenDialog = application.GetWindow("Open", InitializeOption.NoCache);

This doesn't work.

I've also tried the following but this returns null. I thought that I would be able to access this using the LoginForm variable.

Win32ComboBox comboBox = LoginForm.Get<Win32ComboBox>("Filename"); 

Any ideas? Thanks

Aug 17, 2010 at 3:47 PM



can you try


List<Window> windows = application.GetWindows();


Window fileOpen = windows.Where(p=>p.Titel == "Open").First();



Aug 17, 2010 at 4:02 PM

I tried that. I put the first line of code after where I open the file open dialog box

List<Window> windows = application.GetWindows(); gives me 4 elements. The first 3 are the 3 forms and the 4th element is the Open dialog.

Window fileOpen = windows.Where(p=>p.Titel == "Open").First(); caused an exception though, saying sequence contains no elements.

Is there a way to access the fourth element in windows, something like the following. This didn't seem to do anything for me.
Window fileOpen = windows[3];

Aug 17, 2010 at 4:24 PM

maybe p.Titel is incorrect, I#m notz quit sure in the moment


it might be p.Name


you can use

Window fileOpen = windows[3];


but I don'tl ike such calls because the order might be changed or there are less windows, and so on

in my opinion linq expressions are a good way for this.




Aug 18, 2010 at 9:36 AM

Thanks for that. That seemed to work alright. I'm able to click the Cancel button on the file open dialog box.

I now have a new problem. I can't seem to enter text into the file location field.

White Recorder is showing the following:
private White.Core.UIItems.ListBoxItems.Win32ComboBox Filename;

I'm using the following code to write to the box:
Win32ComboBox FileLocationComboBox = fileOpen.Get<Win32ComboBox>("Filename");

FileLocationComboBox is being set to null. This there a different type I need to use to set the value in Filename?

Aug 18, 2010 at 10:48 AM

Never mind! I found out through fileOpen.Items; that there is also a textbox to enter in the file path and file name. I was able to use the following code then.

TextBox FileLocationComboBox = fileOpen.Get<TextBox>("File name:");

Aug 18, 2010 at 10:50 AM



try this


Button open = fileOpen.Get<Button>(SearchCriteria.ByAutomationID("1"));

TextBox box = fileOpen.Get<TextBox>(SearchCriteria.ByAutomationID("1148"));

box.BulkText = "<filepath>";


if open.Click() don't work

you can also use Keyboard class to send "enter" press event

because open button has focus




Aug 18, 2010 at 10:52 AM

use always automation id's to get elements not names. So your tests are operating system language independent


Only the window himself is a problem, because it has no auomation ID