How to handle File download dialog/popup in IE bro

2019-06-18 00:54发布

I have page which downloads a file which shows a dialog on the bottom with OPEN SAVE CANCEL options, how can I click those options ? I am using IE browser, I saw some solutions using third party AutoIt, Robot class, but I am looking with Selenium and C# only. Attached is the image of what I am talking.. Any idea how can we do this ?enter image description here

2条回答
冷血范
2楼-- · 2019-06-18 01:48

You can try this code.

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}");
    }
}
查看更多
来,给爷笑一个
3楼-- · 2019-06-18 01:51
 AutoItX3 autoit = new AutoItX3();
                autoit.WinActivate("Save");            
                Thread.Sleep(1000);
                autoit.Send("{F6}");
                Thread.Sleep(1000);
                autoit.Send("{TAB}");
                Thread.Sleep(1000);
                autoit.Send("{ENTER}");
查看更多
登录 后发表回答