1

Our application has a page where you can upload a file. The code I wrote will use SendKeys() to send the filepath to the input tag of the file upload component. However, it's not working on this page.

string filepath = Path.GetFullPath(Directory.GetCurrentDirectory() + @"\..\..\..\Test Files\" + filename);
uploadInput.Click();
uploadInput.SendKeys(filepath);

I've confirmed that the filepath is definitely correct. I've also confirmed that the WebDriver element is definitely correct as well. And, this code does work on a totally separate form of our application. My guess is that the way this file upload component is coded must not be compatible with this method.

What other options do I have for uploading a file? Note, controlling the System file explorer is totally out of the question given the environment our tests are run in.

EDIT: I confirmed that the input tag is indeed receiving the file I specify. However the form's custom validation seems to think nothing was uploaded. This might be something I need to resolve with our developers.

Andrio
  • 1,852
  • 2
  • 25
  • 54

1 Answers1

0

Try to replace your path from

@"\..\..\..\Test Files\" + filename

to

"\\..\\..\\..\\Test Files\\" + filename

OR

var path= new System.Uri(""\..\..\..\Test Files\" + filename");
var bakedPath = uri.AbsoluteUri;
OriBr
  • 324
  • 2
  • 13