Q:

Selenium: Unable to upload files using for loop in Selenium

I want to upload images on a website, I am using XPath to do it. Using for loop I have tried, the loop is executed but no action is performed.
Please find my code below: 
WebDriver driver=new FirefoxDriver( );
driver.get("https://www.netmeds.com/");
driver.manage().window().maximize();
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
driver.findElement(By.xpath(".//*[@id='carousel-header']/div[1]/div/div[1]/div[3]/div/div[3]/button")).click();

for (int i=1;i<5;i++) {

    driver.findElement(By.xpath(".//*[@id='lbl"+i+"']")).sendKeys("C:\\Users\\sys\\Downloads\\1.png");
    System.out.println("upload");
    driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);

}

A:

Try this code in for loop:
for(int i = 1; i < 5; i++){
            driver.findElement(By.xpath("//input[@id='FileUpload" + i + "']")).sendKeys("C:\\a.jpg");
            driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
            System.out.println("File Upload "+ i + "successfully");
        }

And it works for me:)
second I can use the webDriverwait

