8

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

2 Answers 2

7

The open file dialog is a modal window. You will need to use the LoginForm.ModalWindows() function. From white project wiki:

Window mainWindow = application.GetWindow("main");
List<Window> modalWindows = mainWindow.ModalWindows(); //list of all the modal windows belong to the window.
Window childWindow = mainWindow.ModalWindow("child"); //modal window with title "child"
childWindow.IsModal; //returns true
0

the standard file open dialog box. I can't seem to get a handle on this file open dialog box.

Another solution is just

Window FileOpenDialog = application.GetWindows().Last();

I use that all the time, since when shown (and given that it's modal), the OpenFileDialog is the last window you opened in your application; I can't think of a better one-liner solution for this problem.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.