2016-04-14 6 views
3

Ich habe ein AutoIt-Skript, das ich aus meinem Java-Programm herausrufe, das Selenium verwendet, um Daten über eine Webanwendung zu laden. Das Skript lädt die Datei mit dem Wert aus der Datei, aber nur dann, wenn das Java-Programm im Vordergrund ausgeführt wird. Höchstwahrscheinlich wird dieses Programm im Hintergrund ausgeführt.Kann ich ein Autoit-Skript im Hintergrund ausführen, um eine Datei hochzuladen

Wie kann ich es einrichten, damit das Programm im Hintergrund läuft?

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}") 
+0

Können Sie nicht einfach SendKeys mit Selen verwenden, um die Datei hochzuladen? Ich gehe davon aus, dass dies eine grundlegende Datei-Upload-Schaltfläche ist und nicht irgendeine JavaScript-Bibliothek-Implementierung. –

+1

Ich glaube nicht, dass Sie eine Fokussierung auf ein Hintergrundprogramm setzen können. – IkeRoyle

+0

Nein, ich kann nicht. Auf dem Startbildschirm gibt es kein Textfeld zum Eingeben eines Dateinamens. Sie gehen in ein Cropper-Werkzeug und klicken darauf, um den Datei-Explorer-Dialog zu öffnen. Wenn es nur die Sendkeys in Selen verwendet hätte, hätte ich das getan. – Janet

Antwort

1

ich dieses Problem tatsächlich gelöst, indem das Steuerwort vor den Befehlen. Hier ist mein Skript.

#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 
Verwandte Themen