2016-04-14 63 views
3

我有一個AutoIt腳本,我從我的Java程序中調用,它使用Selenium通過Web應用程序加載數據。該腳本的工作原理是使用文件中的值上傳文件,但只有當Java程序在前臺運行時才能上傳文件。這個程序最有可能會在後臺運行。我可以在後臺運行Autoit腳本來上傳文件

我該如何設置它,以便在後臺運行時程序能夠正常工作?

的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

難道你不只是使用SendKeys Selenium上傳文件?我假設這是基本的文件上傳按鈕,而不是一些JavaScript庫實現。 –

+1

我不認爲你可以專注於後臺程序。 – IkeRoyle

+0

不,我不行。在初始屏幕上沒有輸入文件名的文本框。你進入一個裁剪工具,並在其中點擊打開文件瀏覽器對話框。如果只是在硒中使用sendkeys,我會這麼做。 – Janet

回答

1

我居然通過使用命令之前,控制一詞解決了這個問題。這是我的腳本。

#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