简体   繁体   English

如何使用与wget集成的Selenium WebDriver(Java)下载文件

[英]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.

相关问题 如何在Java中使用Selenium webdriver下载.docx文件? - How to download .docx file using Selenium webdriver in Java? 如何使用 java Selenium WebDriver 下载文件? - How do I download a file using java Selenium WebDriver? 如何在Java中使用Selenium WebDriver上传文件 - How to upload file using Selenium WebDriver in Java 如何使用浏览器堆栈或GRID上的Selenium Webdriver(JAVA)下载文件并检查其内容? - How to download a file using Selenium Webdriver(JAVA) on the browserstack or GRID and check its Content? 如何在Java中使用Selenium Webdriver计算下载文件的大小,状态,剩余时间和传输率 - How to calculate download file Size, Status, Time left and Transfer rate using Selenium Webdriver in java Selenium Webdriver(Java)-文件下载对话框 - Selenium webdriver (java) - file download dialog 如何使用 selenium webdriver 在 chrome 中下载 pdf 文件 - How to download a pdf file in chrome using selenium webdriver 如何使用无头(无GUI)Selenium WebDriver下载文件 - How to download file using headless (gui-less) Selenium WebDriver 如何使用selenium webdriver从第三个网站下载文件 - How to download file using selenium webdriver from a third website 下载文件存储位置和处理使用带有JAVA的selenium webdriver下载弹出窗口 - download file stored Location and handling Download Popup using selenium webdriver with JAVA
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM