How to handle File download dialog/popup in IE browser USING SELENIUM and C#

大兔子大兔子 提交于 2020-02-24 16:13:11

问题


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 ?


回答1:


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}");
    }
}



回答2:


like an option - try get all exist buttons and then filter by inner text

var posibleButtons = driver.FindElements(By.TagName("button")).Where(el => el.Text.Contains("Open"));
posibleButtons.Where(// try use some other filters, maybe by styles or ets...



回答3:


 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}");


来源:https://stackoverflow.com/questions/46565073/how-to-handle-file-download-dialog-popup-in-ie-browser-using-selenium-and-c-shar

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!