1

I'm wondering if there is a way to handle the selection of files or multiple files then click Open on the Windows File Browse dialog using javascript?

The need comes during our Selenium WebDriver test in C# for a file upload. A button is clicked, which launches the Windows Browse.

Currently I have two mechanisms for traversing this dialog and they both involve adding the System.Windows.Forms reference so I can use SendKeys.SendWait. One method sends the file path, sleeps for a second or two then sends Enter. I loop through an array of files using this approach.

The other sends the path of the files, sends enter then a number of tabs to get to the files pane of the dialog. I then send CTRL a, enter and that grabs the files in one lump sum.

However, both methods are inconsistent. The tests will succeed a number of time then seems to get 'lost' during operations in the Browse window.

So, I would like, if possible, to hopefully execute a javascript that will handle the file selections. I know I could then execute the javascript from my Selenium test.

I guess I would have to get a handle on the open window, maybe by name, then I would have to select the files somehow and press enter or the Open button. I really don't care if I have to loop through to get the files I need one by one or multi select to accomplish the task.

So, first, I this even possible. And secondly, does anyone have an example of code or a good starting link to research?

Any help appreciated!!

mawa316
  • 151
  • 1
  • 1
  • 3

0 Answers0