Handling FileUpload Dialogs

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

  

C#

// 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
Manager.DialogMonitor.Start();
  
// Cause the upload Dialog to pop-up
// With Firefox, it is not allowed to pop the dialog using script due to security restrictions.
  
if (ActiveBrowser.BrowserType == BrowserType.FireFox)
{
     // invoke the dialog using a direct mouse click (Click 10 pixels to the left of the right edge of the control)
     Desktop.Mouse.Click(MouseClickType.LeftClick , Find.Elements["uploadfile"].GetRectangle(),
         new Point(-10, 0), OffsetReference.RightCenter);
   
     // Given that we are using pure UI outside the browser, let's make sure we wait for the browser to
     // be ready
     ActiveBrowser.WaitUntilReady();
}
else
{
     // just click it
     Actions.Click(Find.Elements["uploadfile"]);
}
  
// Dialog should be automatically handled

 

Visual Basic

' 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
Manager.DialogMonitor.Start()
  
' Cause the upload Dialog to pop-up
' With Firefox, it is not allowed to pop the dialog using script due to security restrictions.
  
If (ActiveBrowser.BrowserType = BrowserType.FireFox) Then
    ' invoke the dialog using a direct mouse click (Click 10 pixels to the left of the right edge of the control)
     Desktop.Mouse.Click(MouseClickType.LeftClick, Find.Elements("uploadfile").GetRectangle, New Point(-10, 0), OffsetReference.RightCenter)
    ' Given that we are using pure UI outside the browser, let's make sure we wait for the browser to
    ' be ready
     ActiveBrowser.WaitUntilReady()
Else
    ' just click it
     Actions.Click(Find.Elements("uploadfile"))
End If