Upload a file using Selenium

9 views
Skip to first unread message

tester_tester

unread,
Apr 25, 2011, 3:02:21 AM4/25/11
to Selenium Bangalore
Hi All,

Can any one tell me how to upload a file using selenium( Java) using
Auto it

bharathi at

unread,
Apr 25, 2011, 3:15:53 AM4/25/11
to selenium-...@googlegroups.com
Hi
 
U can record Auto it script for browse n upload actions and make it as executable, call it in selenium script.
 
Thanks

Nagi Reddy

unread,
Apr 25, 2011, 3:39:27 AM4/25/11
to selenium-...@googlegroups.com
Hi...
First you can write a simple script in AutoIt and save the file as an executable(.exe).
Ex: attachFile.exe
AutoIt Code:
WinWaitActive("Choose file")
Send("C:\attach\samplefile.txt") \\location of the file you want to attach to the form and submit
Send("{ENTER}")
 
Java Code:
package com.company;     
 import java.io.IOException;
 import com.thoughtworks.selenium.Selenium;
 public class AddAttachment {
    public static void attach(Selenium selenium, String fileName) {
       try {
          String[] commands = new String[]{};
          commands = new String[]{"c:\\test\\attachFile.exe"}; //location of the autoit executable
          Runtime.getRuntime().exec(commands);
       } catch (IOException e) {}
  
       //autoit executable is now waiting for a "Choose file" dialog to popup
       selenium.click("name=browseButton");
       //once the "Choose file" dialog is opened, the autoit will input the path and file name
    }
 }
 
Thanks,
NagarjunReddy K
 
Reply all
Reply to author
Forward
0 new messages