Reputation: 3625
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 ?
Upvotes: 12
Views: 14103
Reputation: 333
Tried in Java, file was downloaded.
driver.findElement(By.xpath("//body")).sendKeys(Keys.chord(Keys.CONTROL, "j"));
Thread.sleep(2000);
Robot rb = new Robot();
rb.keyPress(KeyEvent.VK_ENTER);
Explaination:
1 First click on the button / link to download the file.this pop up will be seen enter image description here
2. Click "Ctrl+j" this will open the "View Downloads pop up".
3.Then click enter , since the focus will be on the recent file, it
will be downloaded
Upvotes: 0
Reputation: 405
IE 11 for security reasons do not allow us to skip that part. Since this is not the DOM, you cannot handle it with selenium..
AutoIT or similar tools are the only option, which makes the test less reliable..
instead, we added API calls to get the documents instead of actually downloading them.
Upvotes: 0
Reputation: 312
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...
Upvotes: 0
Reputation: 21
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}");
Upvotes: 1
Reputation: 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}");
}
}
Upvotes: 0