I'm trying to automate a scenario in which I have to upload document but I couldn't handle the File Upload window once I click the 'Choose File' button on my web application.
I'm using C# language and Chrome browser.
I'm trying to automate a scenario in which I have to upload document but I couldn't handle the File Upload window once I click the 'Choose File' button on my web application.
I'm using C# language and Chrome browser.
My test case in C#:
[Test, Description("JAVA_67350: Filename is shown as tooltip in browse button after upload is cancelled in Firefox browser ")]
[Component(Component.UploadBox)]
[Priority(Priority.High)]
[CustomerID(160100)]
public void JAVA_67350()
{
driver.Navigate().GoToUrl("http://localhost/JavaScript/CR_Samples/JavaScriptSamples/JAVA_67350/UploadBoxUntitled.html");
driver.Manage().Window.Maximize();
Thread.Sleep(3000);
//clicking upload button
driver.FindElement(By.XPath(".//*[@id='UploadDefault']/div[1]/input[2]")).Click();
Thread.Sleep(TimeSpan.FromSeconds(1));
//file uploading
SendKeys.SendWait("C:\\UploadBox\\Examplefordocx.docx" + @"{RIGHT}");
Thread.Sleep(500);
SendKeys.SendWait(@"{TAB}");
Thread.Sleep(500);
SendKeys.SendWait(@"{TAB}");
Thread.Sleep(500);
SendKeys.SendWait(@"{ENTER}");
Thread.Sleep(3000);
}
you can use SendKeys
using System.Windows.Forms;
SendKeys.SendWait(@"C:\temp\file.txt");
SendKeys.SendWait(@"{Enter}");
Selenium doesn't have any inbuilt functions to handle file upload/interacting with windows dialogues(print dialogue)/windows popups.
If you want to interact with windows objects, you can use AutoIT
It is a great tool to interact with windows objects and very easy to use. See the below link for steps to work with.
http://www.toolsqa.com/seleniu-webdriver/autoit-selenium-webdriver/
You can try the following if your File element has 'input type = file'
:
element(by.css('input[type="file"]')).sendKeys(pathToFile);
This will not open up the File upload windows dialog. Rather this will send the required value to the input File field.
You can refer to the following links for details: http://seleniumeasy.com/selenium-tutorials/uploading-file-with-selenium-webdriver
How to upload file using Selenium WebDriver in Java
Regards,
Sakshi