When you are working on the automation part in a testing company, then uploading a file scenario is the most common problem encountered by engineers. There are 2 ways to automate the same.
- Using Selenium
- Using AutoIT
- Using Robot class
We can simply upload the file using Selenium if the HTML contains attribute input[@type='file']. If this is not present in the HTML part of the application, then it will not be possible to upload using Selenium and we would need to look into an alternative. If present, then we can use below syntax for the same.
Once you open the AutoIT editor, you need to write a simple code in AutoIT editor, required for file upload operation (the name of the file to be uploaded, will be mentioned in the code). Now, close the editor and right-click on it, you will see compile script option. Choose compile script (x64) option for 64 bit machine and go with compile script (x86) for a 32-bit machine. As soon as the above step is completed, an .exe file is created and this file will be mentioned in our Selenium Eclipse code. After compilation, ‘fileupload.exe’ file gets created. Now, you can make use of this file in the Selenium WebDriver script.
WebElement upload = d.findElement(By.id("btnSave")); //Uploadbutton
System.out.println("File Uploaded Successfully"); // Confirmation message
When the program executes this line, it goes through the ‘fileupload.exe’ file where the AutoIT code is executed as shown below:
If you have any other questions or concerns about the Selenium web driver or are in general need of QA resources, contact QASource's testing experts.