Sunday, 3 March 2013

AutoIT Example : File Upload

Java Code : 

import java.io.IOException;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;


public class fileUpload2 {
   
    public static void main (String args[])
    {
      
        try {
          

//Run AutoIT script through Java code 

 Runtime.getRuntime().exec("C:\\Users\\Desktop\\Senenium\\Fileupload.exe");


        } 

catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
      
       //Note : Used http://cgi-lib.berkeley.edu/ex/fup.html just for example 

        WebDriver driver=new FirefoxDriver();
        driver.get("http://cgi-lib.berkeley.edu/ex/fup.html");
      
        WebElement upload_btn = driver.findElement(By.name("upfile"));
        upload_btn.click();
    }


 AutoIt v3 Script

Fileupload.au3

WinWaitActive("File Upload")
Send("C:\Users\Downloads\4.jpg")
Send("{Enter}");

No comments:

Post a Comment