java - 如何在不使用 autoIt 和机器人类的情况下使用 selenium webdriver 处理 IE 下载弹出窗口

标签 java selenium selenium-webdriver internet-explorer automation

我必须运行一个脚本来将特定文件下载到 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();
        }       
    }
}

注意:请记住将网络驱动程序路径、网站网址和下载文件夹更改为您自己的。

网站html资源:

 <a id="btnDowloadReport" href="https://github.com//sakinala/AutomationTesting/raw/master/samplefile.pdf" >Download</a>

结果(它将文件下载到所需的文件夹):

enter image description here

关于java - 如何在不使用 autoIt 和机器人类的情况下使用 selenium webdriver 处理 IE 下载弹出窗口,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62085243/

相关文章:

java - driver.switchTo().alert().dismiss();无法在 MS Edge 上运行

mysql - 如何在selenium中导入.sql文件以便我可以在selenium中执行多个脚本?

java - 在线程中使用 Lambda

Java Annotations - 寻找 RetentionPolicy.CLASS 的示例

java - 如何将全局库添加到 IntelliJ IDEA?

java - 如何使用selenium获取网站的值(value)

java - Flipkart.com 价格 slider xpath

java - 矩形内的 OpenGL 渲染

java - 无法使用 Xpath 找到元素

python - WebDriverException : Message: 'The browser appears to have exited before we could connect. 输出为:错误:未指定显示