3

I'm using Selenium webdriver to write an automation testing tool in Java.

This tool will run on a headless server via Jenkins call. My problem is to handle multiple files upload. Selenium can not open browser, so that when I click on upload button on website, the select files popup also not appear.

I'm wondering if there are any other solutions for me to handle the upload multi files during automate testing.

P.S. I can handle single file upload using sendkeys function. But I can not do that to handle multiple files upload.

P.P.S I can not using AutoIT or Robot class to handle the popup dialog (because there is no popup dialog because of headless server)

3
  • 2
    Have you tried to make a String like C:.../f1 \n C:.../f2 and use sendkeys? Put a new line \n after every file.
    – KunLun
    Commented Jun 14, 2018 at 8:12
  • Relevant HTML and code trials? Commented Jun 14, 2018 at 10:09
  • @raul1ro I tried your suggestion and it's working now, you should post an answer for me to accept to help others with same problem
    – TuyenNTA
    Commented Jun 14, 2018 at 10:28

1 Answer 1

5

You can create a String which contain all paths of files

String pathf1 = "...\f1.txt";
String pathf2 = "...\f2.txt";
String pathf3 = "...\f3.txt";
String allF = pathf1 + " \n " + pathf2 + " \n " + pathf3;

And send this String with sendKeys(allF); to your <input>.

I tested on ChromeDriver with an <input type = "file" multiple> and for me worked.

2
  • What about if a website doesn't contain an <input type="file"> element and has a custom upload dialog? Commented Jan 29, 2022 at 20:10
  • @AaronFranke, There should be an input file in code, even if it's not visible. Or for some websites it appears after you interact with some elements. But I suggest to open a question if you have difficulties
    – KunLun
    Commented Jan 31, 2022 at 11:54

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.