-1

I have to upload a .JPG image from a specified folder. Sendkeys(PATH) is not working. The robot is also not working. Please suggest me some other tool like Robot where I can use its .jar files in my maven project. I have to run the code on the server using grid so no installers, please. Any external or internal Java class would be great.

Shubham Jain
  • 16,610
  • 15
  • 78
  • 125
Sujay
  • 139
  • 1
  • 9
  • have u tried sikuli? It has its own API's which can be used along with selenium. http://doc.sikuli.org/faq/030-java-dev.html – nitin chawda Mar 30 '15 at 11:52
  • sikuli requires an install, and won't work if running the tests headless on the server. Integrating sikuli into selenium tests can, at times, be the only option, but it invariably does cause tests to become more brittle and less portable. – aholt Mar 30 '15 at 13:51

2 Answers2

0

Take a look at my answer here. The code is in C#, but it outlines the workaround I used for uploading files inside a selenium test. Note: no third-party tools were required.

Community
  • 1
  • 1
aholt
  • 2,829
  • 2
  • 10
  • 13
0

-> Sendkeys() can be used to upload a file or picture using selenium and Below has given 2 ways of uploading pictures

-> We can use the below code if want to upload a file from the system

driver.findElement(By.id("uploadfile").sendkeys("path of the file");

uploading picture from system with path

-> We can use the below code if want to upload a file stored in the project folder

String projectpath = System.getProperty("user.dir"); //will retrieve the path of the project in workspace
driver.findElement(By.id("uploadfile")).sendKeys(projectpath+"\\path of the folder"); //path of the file which stored in system

created folder in project and uploaded image

uploading picture from project folder path