![](/img/trans.png)
[英]How to download .docx file using Selenium webdriver in Java?
[英]How to download a file using Selenium WebDriver (Java) integrated with wget
我正在嘗試使用WebDriver和wget下載文件。 我的退出值為0,但沒有下載。 我的代碼如下:
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();
}
}
您的wget命令錯誤。 對其進行如下糾正:
String wget_commond = "cmd /c C:/User/TestOptimizer-Raghav/wget -P D: --no-check-certificate " + sourcelocation;
還要檢查下載元素的位置。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.