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