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".

Share this

Related Posts

Next Post »


May 27, 2021 at 10:21 AM delete

I wanted to thank you for this excellent read!! I definitely loved every little bit of it. I have you bookmarked your site to check out the new stuff you post. fire sharing

November 10, 2022 at 11:50 AM delete

Thank you for this. It works fine on dot net core but gives a warning that it only supports .net frameworks


your ad