I need to upload file. Steps are: 1. Clicking on on button which cal modal Window. (Linux window has no location bar) 2. To choose right file and upload it.
Very appreciate any help. Using Chrome Firefox drivers and Java.
I need to upload file. Steps are: 1. Clicking on on button which cal modal Window. (Linux window has no location bar) 2. To choose right file and upload it.
Very appreciate any help. Using Chrome Firefox drivers and Java.
This has been asked several times and is also in some Selenium FAQ.
// assuming driver is a well instantiated WebDriver
WebElement fileInput = driver.findElement(By.xpath("//input[@type='file']"));
fileInput.sendKeys("C:/path/to/file.jpg");
The idea is to directly send the path to the file to an element which you would usually click at to get the modal window - that is <input type='file' />
element.
I find workaround with Robot class
here is code:
try {
Robot robot = new Robot();
robot.delay(3000);
robot.keyPress(KeyEvent.VK_P);
robot.keyRelease(KeyEvent.VK_P);
robot.keyPress(KeyEvent.VK_ENTER);
robot.keyRelease(KeyEvent.VK_ENTER);
} catch (AWTException e) {
e.printStackTrace();
}