File Upload Using Selenium Webdriver and Java Robot Class

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



Leave a reply



Submit