[英]How to download a file using Selenium WebDriver (Java) integrated with wget
I'm trying to download a file using WebDriver and wget. 我正在尝试使用WebDriver和wget下载文件。 I'm getting exit value 0 but download is not happening.
我的退出值为0,但没有下载。 My code is as below:
我的代码如下:
import java.io.IOException;
import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
public class Download {
public static void main(String args[]) throws InterruptedException{
FirefoxDriver driver=new FirefoxDriver();
driver.manage().window().maximize();
driver.get("http://www.thinkbroadband.com/download.html");
Thread.sleep(2000);
WebElement ele=driver.findElement(By.tagName("a"));
String sourcelocation=ele.getAttribute("href");
// String sourcelocation="http://download.thinkbroadband.com/5MB.zip"
// System.out.println("downloadURL="+sourcelocation);
String wget_commond = "cmd /c:/User/TestOptimizer-Raghav>wget no-check-certificate " +sourcelocation;
System.out.println(wget_commond);
try {
Process exec = Runtime.getRuntime().exec(wget_commond);
int exitVal = exec.waitFor();
System.out.println("Exit value: " + exitVal);
System.out.println("Download completed");
} catch (IOException ex) {
System.out.println(ex.toString());
System.out.println("Download failed");
}
driver.quit();
}
}
Your wget command is wrong. 您的wget命令错误。 Correct it as follows:
对其进行如下纠正:
String wget_commond = "cmd /c C:/User/TestOptimizer-Raghav/wget -P D: --no-check-certificate " + sourcelocation;
Also check the location of download element. 还要检查下载元素的位置。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.