1

I'm trying to cancel the pop up download windows in Firefox with selenium. I can switch windows and close alert windows, but I can't seem to select the download window. Any ideas?

Looking around, it seems Selenium RC can't do handle the download window because they depend on the OS. However, is this problem the same for the Selenium Web Driver? I know a solution to this can be done with autoit, but I'd like to keep it all in Java selenium if possible. Thanks.

roverred
  • 1,841
  • 5
  • 29
  • 46

1 Answers1

2

WebDriver cannot directly interact with dialog windows this is because dialog windows are the domain of the operating system and not the webpage. However its possible to do actions on dialog windows using SendKeys class method SendWait() of name space System.Windows.Forms

using System.Windows.Forms;

In the example code below a PLUpload button is pressed, which opens a Windows Dialog to select the file to upload.

Following lines are written to send key values to the dialog window displayed.

SendKeys.SendWait(@"C:\Users\Public\Pictures\Sample Pictures\Dock.jpg");
SendKeys.SendWait(@"{Enter}");

Detailed reference of SendKeys class in C# can be found in http://msdn.microsoft.com/en-au/library/system.windows.forms.sendkeys.aspx

using System;
using System.Windows.Forms;
using OpenQA.Selenium.Firefox;
using OpenQA.Selenium;
using OpenQA.Selenium.Support;
using OpenQA.Selenium.Interactions;
using NUnit.Framework;
namespace BusinessCreation
{
    class PlUpload
    {
        static void Main(string[] args)
        {
            IWebDriver driver = new FirefoxDriver();
            driver.Navigate().GoToUrl("http://www.plupload.com/example_queuewidget.php");
        driver.FindElement(By.XPath("//object[@data='/plupload/js/plupload.flash.swf']")).Click();
           SendKeys.SendWait(@"C:\Users\Public\Pictures\Sample Pictures\Dock.jpg");
           SendKeys.SendWait(@"{Enter}");
        }
     }
}
CheryJose
  • 280
  • 1
  • 6