I am trying to use selenium webdriver to automate web application. So say the dialog below pops up, my goal is to automatically click Save File, and then hit Ok.
Windows Save/Open File DownloadDialouge
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 used 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_queuew idget.php");
driver.FindElement(By.XPath("//object[@data='/plupload/js/pluploa d.flash.swf']")).Click();
SendKeys.SendWait(@"C:\Users\Public\Pictures\Sample Pictures\Dock .jpg");
SendKeys.SendWait(@"{Enter}");
}
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With