0

I am using an AutoIt script to automate my application. Following is the command which I am running:

FileOpenDialog ("File Upload", "C:\Documents and Settings\abhishek.kumar\Desktop\Quadrillion work", "Images (*.jpg;*.bmp)", "","WESTF12433.jpg","" )

Send("{ENTER}")

The first command works as it opens up the file open dialog with WESTF12433.jpg file as selected. Now I want to click on open button. How can I do it?

Send("{ENTER}") is not working.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
coder
  • 319
  • 1
  • 4
  • 17
  • 2
    So wait... You want to create a dialog and then automate on the next line? – Matt Jul 07 '11 at 20:53
  • [XY-problem](https://meta.stackexchange.com/a/66378). Does [this](https://stackoverflow.com/a/50980057/4157124) work as intended (replace file path, and `*.jsxbin` by `*.jpg`)? – user4157124 Jun 23 '18 at 01:51

3 Answers3

6

Send is not a good method as it requires the window to be focused, which you can't guarantee. From what you have posted, I would say the best method would be this:

ControlClick("File Upload", "", "Button1")

Edit in response to comments:

Your problem: The fileOpenDialog is blocking execution. You need to think of it as though AutoIt Reads a line, Runs it, then reads the next.

In this case: AutoIt Reads line 1. It creates a FileOpenDialog and WAITS for you to close it. Once it as been closed it reads the next line, and runs that.

Try the following: Create two au3 files, and put the first line in 1.au3 and the second in 2.au3. Run them in that order and see what happens. Send will struggle as the dialog doesn't have focus, but the ControlClick versions should work.

Matt
  • 7,100
  • 3
  • 28
  • 58
  • Mat is right. ControlClick is always the best choice if you can get the controls ID. For setting text use ControlSetText(). – MemphiZ Aug 12 '11 at 00:12
5

You're not using FileOpenDialog() properly. Its purpose is to interact with the user. If you don't need that, there's no need for it in the first place.

All it does is return the name(s) of the selected files, which you defined already. Can't you just assign the file path to the variable from the start? As per Documentation - Function Reference - FileOpenDialog() :

Success: Returns the full path of the file(s) chosen. Results for multiple selections are "Directory|file1|file2|..."

user4157124
  • 2,809
  • 13
  • 27
  • 42
Chprnk
  • 51
  • 1
  • 4
0

This will never work, because AutoIt is not multi-threaded. Once you open the dialog, it pauses script execution until the user clicks ok, so a Send() function on the next line won't do anything until after.

What you can do is make another script, compile it, and run it just before you open the dialog.

Run("clickOpen.exe")
FileOpenDialog ("File Upload", "C:\Documents and Settings\abhishek.kumar\Desktop\Quadrillion work", "Images (*.jpg;*.bmp)", "","WESTF12433.jpg","" )

This is what would get executed:

WinWaitActive("File Upload")
Send("{ENTER}")

Simple as that! Hope it helps.

hornzach
  • 305
  • 2
  • 5