0

I want to attach a file for upload. Part of a test I am attempting the following but it is not working

1) Enter some details into the input fields    
2) Click Browse on the Web site
3) Enter a file path in the windows popup that appears
4) Click Open on the windows popup
5) Click Apply on the Web site 

Driver.FindElement(By.Id("Name")).SendKeys(name);
Driver.FindElement(By.Id("EmailAddress")).SendKeys(email); 
Driver.FindElement(By.Id("TelephoneNumber")).SendKeys(telephone.ToString());     
Driver.FindElement(By.Name("file")).Click();    
Driver.SwitchTo().ActiveElement().SendKeys("/home/likewise-open/GLOBAL/123/Documents/filename.txt");
Driver.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromSeconds(5));
Driver.FindElement(By.Id("convertButton"));
Dulku
  • 3
  • 2
  • 8
  • 2
    http://stackoverflow.com/questions/11256732/how-to-handle-windows-file-upload-using-selenium-webdriver Possible Duplicate – Ron.B.I Mar 04 '16 at 15:06

2 Answers2

1

Since WebDriver can only handle web based interactions and not windows based ones, you will need the AutoIT utility in order to upload or download and integrate it in Selenium script. AutoIT is a free tool.

H1b1
  • 51
  • 2
  • 10
  • Yes, see my answer here: https://stackoverflow.com/questions/14592853/how-to-upload-a-file-in-selenium-with-no-text-box#48578616 – SharpC Feb 02 '18 at 08:32
1

just try this code

Driver.FindElement(By.Name("yourUploadFileTextBox")).SendKeys("/home/likewise-open/GLOBAL/123/Documents/filename.txt");
Driver.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromSeconds(5));
Driver.FindElement(By.Id("convertButton"));

It will work. No need to click the browse button. Just sendKeys on the textBox where filePath appears.

joinsaad
  • 853
  • 9
  • 13