How to upload a file through automation when testing on LambdaTest?

I would like to know how can I upload a file from my local system through my automation test scripts?

Hi Tom,

The most optimum way to upload your files while testing on LambdaTest would be using the Selenium Localfile detector Library. The Local File Detector allows the transfer of files from the client machine to the remote server.

Here’s a sample code which you can refer to :

     public void upload() {
        try {
            driver.setFileDetector(new LocalFileDetector());

            //Set Selenium Local File Detector


	    //Element for file upload	
            WebElement uploadElement = driver.findElement(By.xpath("//*[@id=\"editArea\"]/div/div/form/fieldset/input[2]"));
	    // Upload file system path
            uploadElement.sendKeys("D:\\New folder\\1.PNG");
            //Click on upload button

	   }  catch (Exception e) {
1 Like