使用此方法进行文件处理:
我们需要 :
jacob.jar下载
它将包含一个 jar 文件和 2 个 .dll 文件
AutoItX4Java.jar下载
public static void uploadFile(String path, String browser){
if(browser.equalsIgnoreCase("chrome")){
if(x.winWaitActive("Open", "", 10)){
if(x.winExists("Open")){
x.sleep(500);
x.send(path);
x.controlClick("Open", "", "Button2");
}
}
}
if(browser.equalsIgnoreCase("firefox")){
if(x.winWaitActive("File Upload", "", 10)){
if(x.winExists("File Upload")){
x.sleep(500);
x.send(path);
x.controlClick("File Upload", "", "Button2");
}
}
}
if(browser.equalsIgnoreCase("InternetExplorer")){
if(x.winWaitActive("Choose File to Upload", "", 10)){
if(x.winExists("Choose File to Upload")){
x.sleep(500);
x.send(path);
x.controlClick("Choose File to Upload", "", "Button2");
}
}
}
}
public void test(){
//Click on the Select button of the file upload
uploadFile("Path", "chrome");
}
谢谢...不要单击接受或赞成,直到它适合您。如果它不适合您的意思,请发表评论..不要投反对票...