FileUpload Dialog

With FileUpload, you need to pass in the full path to the file to upload and how the dialog should be handled. The options for FileUpload are: DialogButton.OPEN, DialogButton.CANCEL or DialogButton.CLOSE.

// Add a FileUpload dialog to be monitored.
Manager.DialogMonitor.AddDialog(new FileUploadDialog(ActiveBrowser, @"C:\EmptyTextFile.txt", DialogButton.OPEN));

// Given that there were no dialog attribute set, the manager will not start the monitoring.
// You need to invoke the monitoring

// Cause the upload Dialog to pop-up
// With Firefox, it is not allowed to pop the dialog using script due to security restrictions.

//Click a button which triggeres the dialog

// Dialog should be automatically handled
' Add a FileUpload dialog to be monitored.
Manager.DialogMonitor.AddDialog(New FileUploadDialog(ActiveBrowser, Path.Combine(Globals.PATH_TO_PAGES, "..\SupportFiles\EmptyTextFile.txt"), DialogButton.OPEN))

' Given that there were not dialog attribute set, the manager will not start the monitoring.
' You need to invoke the monitoring

' Cause the upload Dialog to pop-up

Multiple Files Upload

There are scenarios where multiple files needs to be uploaded. Below you could find a sample code how to obtain that with the Testing Framework. The code will loop through a set of files and will upload each after the previous. The sample is built against a public accessible webpage and to give a try to that example you have to first navigate to that page.

// place small pictures with names file1.png and file2.png in c:\temp folder to have the sample working without modification
string path = @"C:\temp\" ;
string[] fileNames = new string[] { "file1.png", "file2.png" } ;

// locate the frame on page
FrameInfo frInf = new FrameInfo("iframeResult", "", "", 0);
Browser frame = ActiveBrowser.Frames[frInf];

// locate file browse button
HtmlInputFile uploadBtn = frame.Find.ById<HtmlInputFile>("myFile");
// locate Submit button
HtmlInputSubmit submitBtn = frame.Find.ByAttributes<HtmlInputSubmit>("type=submit");

for (int i = 0; i < fileNames.Length; i++ )
    // add a FileUpload dialog to be monitored
    FileUploadDialog uploadDialog = new FileUploadDialog(ActiveBrowser, path + fileNames[i] , DialogButton.OPEN);

    // start the Dialog Monitoring

    // click on the button which triggeres the dialog

    // wait on handling the dialog for 10 seconds

    // The dialog should be automatically handled

    // Click 'Submit' to upload the file

    // execution delay to check on the uploaded content - 2 seconds

    // Refresh the page to be ready to upload next file

Note: To compile the above code include the following using:

using ArtOfTest.WebAii.Win32.Dialogs;

See Also

Is this article helpful? Yes / No
Thank you for your feedback!

Give article feedback

Tell us how we can improve this article