使用此方法用於文件處理:
我們需要:
Ĵ acob.jar Download
它將包含一個jar文件和2個.dll文件
AutoItX4Java.jar Download
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");
}
謝謝...不要單擊接受或給予好評,直到它爲你工作。如果它不爲你工作方式,請評論..不要Downvote ...
不要點擊上傳按鈕。只需要執行'driver.findElement(By.name(「uploadFile」))。sendKeys(「E:\\ DVBScheduleEvent.xml」);'' – Arran