0

I am testing automation with selenium and stuck here When i click a button and a new popup window will open(just as OpenFileDialog) to select file from computer. I want to write a testcase for this step. Please help!!!

sonas sonas
  • 197
  • 1
  • 5
  • 15
  • A good explanation about this topic is provided [HERE](http://stackoverflow.com/questions/9431978/one-solution-for-file-upload-using-selenium-webdriver-with-java) – Amith Oct 18 '13 at 07:30

2 Answers2

2

There are two ways to handle this as,

  1. Directly pass the file as,

    driver.findElement(By.id("elementId")).sendKeys("C:\path\to\your\file");

  2. By using the Robot framework click here.

Hope this will help you.

Community
  • 1
  • 1
Chetan
  • 2,360
  • 3
  • 18
  • 33
0

Use this Method for file handling:

We need :

jacob.jar Download

It will contain one jar file and 2 .dll files

AutoItX4Java.jar Download

public static void uploadFile(String path, String browser){

    if(browser.equalsIgnoreCase("chrome")){

        if(x.winWaitActive("Open", "", 10)){
            if(x.winExists("Open")){
                x.sleep(500);
                x.send(path);
                x.controlClick("Open", "", "Button2");

            }
        }

    }


    if(browser.equalsIgnoreCase("firefox")){

        if(x.winWaitActive("File Upload", "", 10)){
            if(x.winExists("File Upload")){
                x.sleep(500);
                x.send(path);
                x.controlClick("File Upload", "", "Button2");

            }
        }
    }

    if(browser.equalsIgnoreCase("InternetExplorer")){

        if(x.winWaitActive("Choose File to Upload", "", 10)){
            if(x.winExists("Choose File to Upload")){
                x.sleep(500);
                x.send(path);
                x.controlClick("Choose File to Upload", "", "Button2");

            }
        }
    }



}


   public void test(){
       //Click on the Select button of the file upload
       uploadFile("Path", "chrome");


   }

Thanks... Dont click Accept or Upvote until it works for you. If it is not working for you means, please comment.. Dont Downvote...

Prabu Ananthakrishnan
  • 4,139
  • 1
  • 12
  • 16