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();
}
}
}
网友评论