If you have a text box to enter the path to the file, just use sendkeys to enter the path to the file and click the submit button. If there is no text box to enter the path to the file and just click the browse button and select the file from the popup window, you can use the AutoIt tool, see the next step to use AutoIt for this,
Download and install the Autoit tool from http://www.autoitscript.com/site/autoit/
Open Programs → Autodiscover Tool → SciTE Script Editor.
Paste the following code into the Autoit editor and save it as "filename.exe" (for example: new.exe)
Then compile and create the file to make it exe. (Tools → Compile)
Startup Code:
WinWaitActive("File Upload"); Name of the file upload window (Windows Popup Name: File Upload) Send("logo.jpg"); File name Send("{ENTER}")
Then compile and compile from the Tools menu of the Autoit tool → SciTE Script.
Paste the Java code below into the Eclipse editor and save
Java Code:
driver.findElement(By.id("uploadbutton")).click; // open the Upload window using selenium Thread.sleep("20000"); // wait for page load Runtime.getRuntime().exec("rundll32 url.dll,FileProtocolHandler " + "C:\\Documents and Settings\\new.exe"); // Give path where the exe is saved.
user3903359 Aug 03 '14 at 6:02 2014-08-03 06:02
source share