美文网首页我爱编程
selenium下载文件

selenium下载文件

作者: 红木杉2018 | 来源:发表于2017-03-21 17:17 被阅读0次

    package com.selenium.gen;

    import java.awt.AWTException;

    import java.awt.Robot;

    import java.io.IOException;

    import org.openqa.selenium.By;

    import org.openqa.selenium.WebDriver;

    import org.openqa.selenium.firefox.FirefoxDriver;

    import org.openqa.selenium.firefox.FirefoxProfile;

    import org.openqa.selenium.interactions.Actions;

    import com.thoughtworks.selenium.webdriven.commands.KeyEvent;

    public class Download {

    public static void main(String[] args) throws AWTException, IOException {

    // TODO Auto-generated method stub

    FirefoxProfile firefoxprofile=new FirefoxProfile();

    //设置保存到指定目录

    firefoxprofile.setPreference("browser.download.folderList", 2);

    //是否显示开始

    firefoxprofile.setPreference("browser.download.manager.showWhenStarting",false);

    //指定文件下载目录

    firefoxprofile.setPreference("browser.download.dir", "d:\\jase");

    //指定要下载页面的 Content-type 值,“application/octet-stream”为文件的类型

    firefoxprofile.setPreference("browser.helperApps.neverAsk.saveToDisk","application/octet-stream");

    WebDriver driver=new FirefoxDriver(firefoxprofile);

    driver.get("https://pypi.Python.org/pypi/selenium");

    Actions action=new Actions(driver);

    action.click(driver.findElement(By.linkText("selenium-3.0.2.tar.gz"))).perform();

    Runtime.getRuntime().exec("C:\\Users\\user\\Desktop\\click.exe");

    try {

    Thread.sleep(5000);

    } catch (InterruptedException e) {

    // TODO Auto-generated catch block

    e.printStackTrace();

    }

    }

    }

    相关文章

      网友评论

        本文标题:selenium下载文件

        本文链接:https://www.haomeiwen.com/subject/pppgnttx.html