How to Upload file in selenium using c#

How to Upload file in selenium using c#

We are facing a problem when we have a situation like an upload file in the server in the automation testing because most of the cases we have seen upload dialog box is not a web-based popup, it is a window-based popup. 

File upload box

Currently, Selenium can not handle it because it only supports web-based applications only, so we need to take help from 3rd party applications like autoIT or robot to handle this kind of popup. 

But we can handle this upload popup without any 3rd part application if we use C# language for selenium. There is a NuGet package available in .NET which can handle this upload pop up without any 3rd party applications. 

Package name: OpenDialogWindowHandler -v0.0.0.1

You need to import it from the NuGet package manager before using it inside the class.

Method to upload file

public void UploadFile(string filepath,string filename){
    HandleOpenDialog hndOpen =  new  HandleOpenDialog();

There first we need to create an object of HandleOpenDialog and then call the function
fileOpenDialog(). This function has 2 parameter 1st one is file path eg.  "c:\\helpfile"
and next one is file name. eg "help.txt".

your ad