Uploading a file in Selenium C#

Uploading a file in Selenium is easy, you need not click on the Window dialog box and browse through the folder location to select a file if the input type is “file”

For e.g let us say you have an input box with type as file

<input type='file' name='fileupload'>

Then allow you have to is call a Selenium code like this

 

//Uploading a file called "Products.xls"

public void FileUpload()
{
    //The first step gets the base directory and the file
    string File = AppDomain.CurrentDomain.BaseDirectory + "\\" + "Products.xls";
    Browser.FindElement(By.Id("File"), LongLongWaitTime).SendKeys(File);

}

 

You may also like...