Introduction
This tip will help you to select file for file upload using Selenium web driver.
Background
You need basic knowledge of Selenium web driver to use this.
Using the Code
First create web driver object:
IWebDriver driver = new ChromeDriver();
Then find the FileUpload
input field by using xpath
or id
or ny
object:
IWebElement ele = driver.FindElement(By.XPath(DOMName));
Click the file upload button:
ele.Click();
Sleep thread for 2 seconds to open the file select window:
Thread.Sleep(2000);
Send the location of the file to be uploaded:
SendKeys.SendWait(FilePath);
Finally, send enter key to select the path:
SendKeys.SendWait("{Enter}");
IWebDriver driver = new ChromeDriver();
IWebElement ele = driver.FindElement(By.XPath(DOMName));
ele.Click();
Thread.Sleep(2000);
SendKeys.SendWait(FilePath);
SendKeys.SendWait("{Enter}");
By using the steps as mentioned above, you will easily select a file for file upload. Also, we have provided a thread sleep for 2 seconds which is not mandatory but you will need it when file selection window comes slow on your machine.
Points of Interest
You will finally select the file to upload it using the Selenium web driver. See check box selection on my next article.
History
- 4th January, 2019: Initial version