selenium+eclipse下载文件时遇到的问题
步骤:1 电脑下载wget64.exe 到C盘Wget文件夹下,在命令行窗口测试可以下载文件。 2 运行如下代码,下载路径查看,文件大小为110k就不再增加,正确的文件大小应为430k。打开任务管理器查看,wget仍运行。(在命令行窗口直接运行下载命令可以下载此文件)data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAn8AAABECAIAAAB/DsTrAAANAUlEQVR4nO2d3W8bWRmH83/kH2mkFQjSRRErRFcIIYRaxIWlZqUIC7ZFu8BC21Ws1VI3u+DtblFwhdQKkLggvrGvek9AvkCKgsIF2ipt0qROncnMZM5MAhfjmTnf59iZju3x75FVxeMzM2fs6Tzzvudj5iIt6+vrzvHxyfGx6zjuyYnnnviu63veqe8Hp6ckOCUkWF9fl6y5XV+Yi6m0oiiKWpW5hfp2/Jni71ZlsMbcQr1OFQFgvHSbKwy19m4URVG0264NljS7g6LZIuaD3XYtXSstyC7I9pIu58ooqkHtMq0GjbRKsoV0JcXKqA4tbwZ7TrYev2W+qt12jdt3t/m6agNyRPL/hYH9GbvN5IdnT/zy/NJz+o/X1tacft857icCdlgB+yQ4XVtbK6auAJSGbpOz8YhlykR8bdbdQcRfB+wLSoHBvqurq8evXqUCPpEJeHV1tZi6AlAWIF8AZh2Dfd+3o5i6AgAAAOXAYF8AAAAA5A7sCwAAABQN7AsAAAAUDewLAAAAFA3sCwAAABQN7AsAAAAUjdK+9z69P9SryEoDAAAAU43Ovv/6939Vr+vvfUL/C/sCAAAA9ujs+/d//NPyBfsCAHJGMX8kP9+0avLp3XZtZaXW7grFZRvFxGKgcHT2/Z/A+fn5+fn52dlZGIZBEHied3Jy0u/3i7Zvq5I+vcGwEIBckD/KQPIsgnSx8sEL4jMDVppdbip5zgRJGVM11JMds1WyWEtyaLoavhbkSmSePcHM+Tx4k3xJ8QfcrNCZ0vmHVuh+JKBFcnbpTzn5l8vcbsW/YrMbjeHEKwiDfd945+FXfvyHr934/eVffL70YUO07xvvPCzWvtv1hbm5hUplgRatdC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63TDqBrEJDz7ahicVJw7W2r3ikI862MUhZo/UXTBuwLwB5MA77KmxH/CX7cHAI+2rlGkUGN4v2FdPs1MEOM9Nk7OaRGtoBGBuwLwB5YLKvfEiu0r6pnJT2FaNe+sM4lFQLKR1/bDtds3Z36aY0Ihcyz5xfJV63f8oCHzoDMPnAvgCMTtaztxrQOnEbhBvy6zZIFAUep4dOwL5nY9+Or/Bi4FmEeoO6yaNVutuwudeSMpQ3GxQAIAf2BWByMI44ynmK46Bh9KWV6bmJNgEARmBfAAAAoGhgXwAAAKBoYF8AAACgaP4P1onEOG0fKk8AAAAASUVORK5CYII=
代码如下:
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();
}
}
已解决,修改trycatch 部分为
catch (InterruptedException | IOException ex) {
System.out.println(ex.toString());
}
页:
[1]