如何在不使用 autoIt 和机器人的情况下使用 selenium webdriver 处理 IE 下载弹出 class
How to handle IE download pop up with selenium webdriver without using autoIt and robot class
我必须 运行 一个脚本来将特定文件下载到 Internet Explorer 中的所需文件夹,而无需使用 AutoIt 和机器人。除了这个还有别的办法吗。我是自动化新手。
enter image description here
enter image description here
我使用了下面的代码,在我这边运行良好,请检查一下:
package seleniumtest;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.ie.InternetExplorerDriver;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;
import java.io.IOException;
public class testsample {
//@SuppressWarnings("deprecation")
public static void main(String[] args) {
//add the IE web driver path here..
System.setProperty("webdriver.ie.driver","E:\webdriver\IEDriverServer_x64_3.14.0\IEDriverServer.exe");
WebDriver browser = new InternetExplorerDriver();
//replace the URL of the web page here..
browser.get("<website url>");
WebDriverWait wait = new WebDriverWait(browser, 5);
wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("btnDowloadReport")));
WebElement element = browser.findElement(By.id("btnDowloadReport"));
String downloadurl = element.getAttribute("href");
System.out.println(downloadurl);
String command = "cmd /c E:\\Temp\\wget.exe -P E:\\Temp\\output\\ --no-check-certificate " + downloadurl;
try {
Process process = Runtime.getRuntime().exec(command);
process.getErrorStream();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
注意:请记得将网络驱动程序路径、网站url和下载文件夹更改为您自己的。
网站html资源:
<a id="btnDowloadReport" href="https://github.com//sakinala/AutomationTesting/raw/master/samplefile.pdf" >Download</a>
结果(它将文件下载到所需的文件夹):
我必须 运行 一个脚本来将特定文件下载到 Internet Explorer 中的所需文件夹,而无需使用 AutoIt 和机器人。除了这个还有别的办法吗。我是自动化新手。 enter image description here enter image description here
我使用了下面的代码,在我这边运行良好,请检查一下:
package seleniumtest;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.ie.InternetExplorerDriver;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;
import java.io.IOException;
public class testsample {
//@SuppressWarnings("deprecation")
public static void main(String[] args) {
//add the IE web driver path here..
System.setProperty("webdriver.ie.driver","E:\webdriver\IEDriverServer_x64_3.14.0\IEDriverServer.exe");
WebDriver browser = new InternetExplorerDriver();
//replace the URL of the web page here..
browser.get("<website url>");
WebDriverWait wait = new WebDriverWait(browser, 5);
wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("btnDowloadReport")));
WebElement element = browser.findElement(By.id("btnDowloadReport"));
String downloadurl = element.getAttribute("href");
System.out.println(downloadurl);
String command = "cmd /c E:\\Temp\\wget.exe -P E:\\Temp\\output\\ --no-check-certificate " + downloadurl;
try {
Process process = Runtime.getRuntime().exec(command);
process.getErrorStream();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
注意:请记得将网络驱动程序路径、网站url和下载文件夹更改为您自己的。
网站html资源:
<a id="btnDowloadReport" href="https://github.com//sakinala/AutomationTesting/raw/master/samplefile.pdf" >Download</a>
结果(它将文件下载到所需的文件夹):