0

我正在尝试使用 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();
    }
}
4

1 回答 1

0

Your wget command is wrong. 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.

于 2016-03-31T14:13:39.473 回答