TA的每日心情 | 郁闷 2017-9-11 10:41 |
---|
签到天数: 16 天 连续签到: 1 天 [LV.4]测试营长
|
步骤:1 电脑下载wget64.exe 到C盘Wget文件夹下,在命令行窗口测试可以下载文件。 2 运行如下代码,下载路径查看,文件大小为110k就不再增加,正确的文件大小应为430k。打开任务管理器查看,wget仍运行。(在命令行窗口直接运行下载命令可以下载此文件)
代码如下:
public class test3 {
public static void main(String[] args) throws InterruptedException {
System .setProperty("webdriver.chrome.driver",
"C:\\Program Files (x86)\\Google\\Chrome\\Application\\chromedriver1.exe");
WebDriver driver=new ChromeDriver();
String baseUrl = "http://demo.guru99.com/selenium/yahoo.html";
driver.get(baseUrl);
WebElement downloadButton = driver.findElement(By.id("messenger-download"));
String sourceLocation = downloadButton.getAttribute("href");
String wget_command = "cmd /c C:\\Wget\\wget64.exe -P C: --no-check-certificate " + sourceLocation;
try {
Process exec = Runtime.getRuntime().exec(wget_command);
int exitVal = exec.waitFor();
System.out.println("Exit value: " + exitVal);
System.out.print(wget_command);
} catch (IOException e) {
e.printStackTrace();
}
driver.close();
}
}
|
|