3

I have an AutoIt script that I call from my Java program that is using Selenium to load data through a web application. The script works to upload the file using the value from the file but only when the Java program runs in the foreground. Most more than likely this program will run in the background.

How can I set it up so that when running in the background the program will work?

Java:

Thread.sleep(2000); // wait for page load   
Runtime.getRuntime().exec("C:\\Users\\Janet\\Documents\\uploadFile.exe " + uploadFile);

AutoIt:

#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_Outfile=C:\Users\Janet\Documents\uploadFile.exe
#AutoIt3Wrapper_Outfile_x64=C:\Users\Janet\Documents\uploadFile_x64a.Exe
#AutoIt3Wrapper_Compile_Both=y
#AutoIt3Wrapper_UseX64=y
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
ControlFocus("File Upload","","Edit1"); Name of the file upload window (Windows Popup Name: Open)
ControlSetText("File Upload","","Edit1",$CmdLineRaw); File name
Send("{ENTER}")
user4157124
  • 2,809
  • 13
  • 27
  • 42
Janet
  • 251
  • 1
  • 2
  • 11
  • Could you not just use SendKeys with Selenium to upload the file? I'm assuming this is basic file upload button and not some javascript library implementation. – Ben C Apr 14 '16 at 15:01
  • 1
    I don't think you can set a focuse on a background program. – IkeRoyle Apr 15 '16 at 07:19
  • No I can't. On the initial screen there is no text box to enter a file name. You go into a cropper tool and click within that to open the file explorer dialog. If it was just using the sendkeys in selenium I would have done that. – Janet Apr 18 '16 at 12:18

1 Answers1

1

I actually resolved this issue by using the word Control before the commands. Here is my script.

#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_Outfile=C:\Users\Janet\Documents\uploadFile.exe
#AutoIt3Wrapper_Outfile_x64=C:\Users\Janet\Documents\uploadFile_x64a.Exe
#AutoIt3Wrapper_Compile_Both=y
#AutoIt3Wrapper_UseX64=y
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
;
;*   Script Name:   uploadFile.au3
;*   Author:        Janet Frank
;*   Date Created:  04/04/16
;*   Description:
;*     This script receives a file name from a Java program that needs to upload a file for the purpose
;*     of a profile image or an asset to the VTS site.   The file name is passed from the Java program
;*     via the command line used to execute this script.  Using the $CmdLineRaw function the program can
;*     extract that file name from the command line.
;
ControlFocus("File Upload","","Edit1"); Name of the file upload window (Windows Popup Name: File Upload)
ControlSetText("File Upload","","Edit1",$CmdLineRaw); File name passed from Java program
ControlSend("File Upload","","Button1","{Enter}") ;Press the Enter key whe on the Open button to exit the file explorer.
Exit
user4157124
  • 2,809
  • 13
  • 27
  • 42
Janet
  • 251
  • 1
  • 2
  • 11