2016-04-14 140 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