How to add multiple files in Selenium Web-driver using Java



  • In automation testing, I have successfully uploaded a single file multiple times using Selenium webDriver, but the project I'm working on now requires multiple file upload at a single time. So, my automation test case also has multiple uploads at once. But I have no clue how to add multiple files at once in Selenium.



  • In my case, I am already using a CSV file to fill data. So I made logic to add multiple files using the CSV file which I was using to add data (Form Filling).

    Each Form filling data is stored in a row, so to fill new form I jumped to the next row and filled the form. So to add multiple files in a single form I added file paths like form data in a single row. So each cell in a row contains a separate file path. And then I fetched the file paths in a row using CSVReader & readNext for each and every cell I find the last cell in a row. That's how I was able to add multiple files.

    Sample Code:-

    for(int i=1 ;i<strs.size() ;i++) //loop for scanning row by row data
        {
            for(int j=7;j<=strs_2.length;j++) //loop for scanning multiple file paths in a single row
            {
                 driver.findElement(By.xpath("xpath of element")).sendKeys(csvCell[(j)]);
            }
        }
    


Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2