如何在IE浏览器中使用SELENIUM和C#处理文件下载对话框/弹出窗口

msb*_*uva 8 selenium internet-explorer file download

我有一个页面下载一个文件,该文件在底部显示一个对话框,带有OPEN SAVE CANCEL选项,如何点击这些选项?我使用IE浏览器,我看到了一些使用第三方AutoIt,Robot类的解决方案,但我只看Selenium和C#.附上我正在谈论的形象..任何想法我们怎么能这样做?在此输入图像描述

小智 0

你可以试试这个代码。

using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using OpenQA.Selenium;
using OpenQA.Selenium.IE;    
using OpenQA.Selenium.Support.UI;
using System.Threading;
using System.Collections.Generic;
using System.Windows.Forms;
//using NUnit.Framework;

namespace SampleTest
{
    [TestMethod]
    public void Download()
    {
        IWebDriver driver = new InternetExplorerDriver(@"C:\Users\hamit\Desktop\Selenium\IEDriverServer_Win32_2.48.0");
        driver.Navigate().GoToUrl("https://www.spotify.com/se/download/windows/");

        Thread.Sleep(2000);
        SendKeys.SendWait("@{TAB}"); Thread.Sleep(100);
        SendKeys.SendWait("@{TAB}"); Thread.Sleep(100);
        SendKeys.SendWait("@{DOWN}"); Thread.Sleep(100);
        SendKeys.SendWait("@{DOWN}"); Thread.Sleep(100);
        SendKeys.SendWait("@{Enter}");
    }
}
Run Code Online (Sandbox Code Playgroud)