Below is the AUTO It Script for Mutiple Files
$vVariable = """C:\Users\NEERAJ\Desktop\Manage_Plugins.jpg"" ""C:\Users\NEERAJ\Desktop\Manage_Plugins1.jpg"""
ControlFocus("File Upload","","Edit1")
Sleep(2000)
Sleep(2000)
ControlSetText("File Upload", "", "Edit1" ,$vVariable)
Sleep(2000)
Note:Here we are using double quotes , because when we upload multiple files the files are seperated with double quotes.
Example: " "filename1" "filename2" "
Refer below Screenshot

Refer Below Working Script
package mypackage;
import java.io.IOException;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
public class myclass {
public static void main(String[] args) throws IOException, InterruptedException {
WebDriver driver = new FirefoxDriver();
String baseUrl = "https://davidwalsh.name/demo/multiple-file-upload.php";
driver.get(baseUrl);
driver.findElement(By.xpath(".//*[@id='filesToUpload']")).click();
Thread.sleep(4000);
Runtime.getRuntime().exec("C:\\Users\\NEERAJ\\Desktop\\NewUpload.exe");
}
}
Using Robot Class
Robot robot = new Robot();
robot.delay(1000);
// Type file path
StringSelection ss = new StringSelection("C:\\Users\\Neeraj\\Documents\\sample.pdf");
Toolkit.getDefaultToolkit().getSystemClipboard().setContents(ss, null);
// Ctrl + V to paste
robot.keyPress(KeyEvent.VK_CONTROL);
robot.keyPress(KeyEvent.VK_V);
robot.keyRelease(KeyEvent.VK_V);
robot.keyRelease(KeyEvent.VK_CONTROL);
// Press Enter
robot.keyPress(KeyEvent.VK_ENTER);
robot.keyRelease(KeyEvent.VK_ENTER);
No comments:
Post a Comment