One solution for File Upload using Java Robot API with Selenium WebDriver by Java
Actually, there is an in-built technique for this, too. It should work in all browsers and operating systems.
Selenium 2 (WebDriver) Java example:
// assuming driver is a healthy WebDriver instance
WebElement fileInput = driver.findElement(By.xpath("//input[@type='file']"));
fileInput.sendKeys("C:/path/to/file.jpg");
The idea is to directly send the absolute path to the file to an element which you would usually click at to get the modal window - that is <input type='file' />
element.
Robot Class is not working for file upload in IE 11 in Selenium webDriver
Try once by writing robot.delay(10000);
before comment //Press Enter
Other simple alternative for uploading file without robot class :
driver.findElement(By.xpath(".//input[@type='file']")).sendKeys("C:\\Users\\m9kuil\\Desktop\\ImportAttendeeTemplate.xlsx");
wait(10000)
Related Topics
How Can a Keylistener Detect Key Combinations (E.G., Alt + 1 + 1)
Main Method Not Found Even If I'Ve Declared It
Retrieving Servlet Context, Session and Request in a Pojo Outside Container
Printf %F with Only 2 Numbers After the Decimal Point
Collision Detection Between Two Images in Java
Reading a Specific Line from a Text File in Java
Case Insensitive JSON to Pojo Mapping Without Changing the Pojo
How to Write and Read Java Serialized Objects into a File
Scanner Class Skips Over Whitespace
"Content Is Not Allowed in Prolog" When Parsing Perfectly Valid Xml on Gae
Convert Xml to Java Object Using Jaxb (Unmarshal)
No Idea Annotations Attached to the Jdk 1.8 (C:\...), Some Issues Will Not Be Found
Get Key Press Without Pressing Enter in Console
Null Pointer Exception While Using Java Compiler API
Java Key Listener in Commandline
How to Change Java Logging Console Output from Std Err to Std Out