Pages

Search This Blog

Sunday, September 26, 2010

How to upload a file in selenium with the help of AutoIT

How to upload a file in selenium with the help of AutoIT
Recently, I had the challenge of writing some automation for a work flow which included uploading a file because uploading a file works on windows component.
selenium is unable to access windows components and it will be handled through AutoIT.
Once you are able to click on browse button and a dialog box is open to choose the file then you just run a AutoIT script which will help to select the file from your local or remote drive and control will come to your web page to proceed with selenium.

Step to choose a file from your local or remote drive

Step 1.

Click on browse button on your web page and go to second step.If you are unable to click on browse button then visit below page.

How to click on browse button

setp 2.
write a AutoIT script to choose a file from your local or remote drive.

WinActivate("Choose file");
Local $file = "c:\yourpath\howtoupload.doc"
ControlSetText("Choose file", "", "Edit1", $file )
ControlClick("Choose file", "", "Button2")



setp 3.
Complie AutoIT script and make exe of that script.

Right click on that saved script file and click on "Compile script" from context menu. This will make an exe file of that script.

setp 4.
Call that exe in selenium.

Process proc = Runtime.getRuntime().exec("C:\\Documents and Settings\\nirkumar\\Desktop\\Browse.exe");


Download AutoIT script
Download exe file of AutoIT script

If you want to test this script then just download the script exe file and click on browse button on web page and run this exe file. Just make sure you have your file in correct path by changing this line of script in the second step
Local $file = "c:\yourpath\howtoupload.doc"
in above line of script change your file path then make exe of your script then click on browse button on your web page then run this exe . I am sure this would work.
If it still is nor working then change the script like

WinActivate("File Upload");
Local $file = "c:\yourpath\howtoupload.doc"
ControlSetText("File Upload", "", "Edit1", $file )
ControlClick("File Upload", "", "Button2")

20 comments:

  1. but how to click browse button at all. I was unable to click on browse button in Fire Fox. Even with IDE unable to record the script

    ReplyDelete
    Replies
    1. For clicking on browse button you need to follow below process
      http://automationtricks.blogspot.in/2010/09/how-to-click-on-browse-button-in.html

      Delete
  2. the file upload with autoit don't work

    ReplyDelete
  3. I used follwoing script to run autoit exe

    System.out.println("before Auto it exe");
    String[] commands = new String[]{};
    commands = new String[]{"E:\\AutoIt\\FileUpload.exe"};

    Runtime.getRuntime().exec(commands);
    Thread.sleep(5000);

    System.out.println("Auto it is executed");

    i am not able to run exe

    ReplyDelete
  4. HI Niraj,

    I tried the same with Selenium RubyRspec with cucumber. It is not working for me. It would be great help if you have any idea of doing Fileupload using SeleniumRC with Ruby

    Thanks
    Krishna

    ReplyDelete
    Replies
    1. Not working for me too

      Delete
    2. can anyone help me in uploading multiple photos using the same way

      Delete
  5. HI I tried as u told, But its not working

    ReplyDelete
  6. Hi Niraj,
    I m getting Autoit error as unable to open the script file. Please can u provide solution to solve it

    ReplyDelete
  7. Thanks for sharing great information in your blog. Got to learn new things from your Blog . It was very nice blog to learn about Selenium

    ReplyDelete
  8. Thanks for sharing great information in your blog. Got to learn new things from your Blog . It was very nice blog to learn about Selenium.
    Selenium

    ReplyDelete
  9. It was very nice blog to learn about SAP BASIS. Thanks for sharing.SAP basis

    ReplyDelete
  10. It was very nice blog to learn about Selenium.Thanks for sharing new things.selenium training in chennai

    ReplyDelete
  11. The blog gave me idea to upload file in selenium using auto IT my sincere thanks for sharing this post please countinue to share this kind post
    Selenium Training in Chennai

    ReplyDelete
  12. nice blog you had been shared.. so keep on sharing such kind of an interesting articles. before i read this blog i didn't have any knowledge but now i got some knowledge.
    selenium training in chennai

    ReplyDelete
  13. Really its very useful blog. I have read this blog. It's helpful for me my friend. Also great blog here with all of the valuable information you have.
    Software Testing Training in Chennai | Selenium Training in Chennai

    ReplyDelete
  14. I wish I had your imaginative journalism skills, progressive talent and self-discipline to produce a blog like you did. Your blog really does deserve an honest compliment.
    Software Testing Training in Chennai
    Software Testing Training Institute in Chennai

    ReplyDelete
  15. This comment has been removed by the author.

    ReplyDelete
  16. http://www.kitsonlinetrainings.com/abinitio-online-training.html

    ReplyDelete