Home > Automation Testing > Advance Selenium > File Upload Using Windows Automation Tool And Selenium

File Upload Using Windows Automation Tool And Selenium

Here are the step to upload file using selenium

  1. Click on Select file / Select button (This part could be handled using Selenium)
  2. Select file from open dialogue box(This part could not be handled using selenium) 
  3. Click on Upload or Upload file button.

File Upload for INPUT tag with TYPE =”file”

Example Url: 

If Select file button is input tag like

<input id="fileupload" type="file" name="files[]"> 

Create element for file upload input box 

@FindBy(how = How.NAME, using = "upfile") WebElement fileUpload; 

Send file path sendKeys(CharSeq..) function

fileUpload.sendKeys(filePath); 

Not every time Input tag used for file upload in that case we need to handle window’s open file dialog box.

In that case below mentioned solution will be useful.

File Upload for Other tags.

In this case we need handle OpenFileDialog box which will be opened after click on select file button.

To handle OpenFileDialog we required following tools

      1. WinAppDriver UI Recorder v1.1 Used to find windows locator.
      2. Winium.Desktop.Driver.exe Used to handle windows elements.
        Java Library required
      3. winium-webdriver-0.1.0-1.jar
      4. winium-elements-desktop-0.2.0-1.jar

How to use WinAppDriver UI Recorder V1.1?

  1. Unzip downloaded WinAppDriverUIRecorder.zip – ZIP archive and open “WinAppDriverUiRecorder.exe” file.
  2. Open url “https://cgi-lib.berkeley.edu/ex/fup.html”  and click on “choose file” select file open dialog box will be opened.
  3. Click on “Record” Button in WinAppDriverUiRecorder.
  4. Move mouse cursor to file name input box OR open button wait until button or input box highlighted, then click on pause button. It will generate xpath, we could use class name or name from that xpath.
    Example:

Project Structure and code

  1. Create java project and add Selenium jar files and TestNG library.
  2. Add downloaded jars to the project winium-webdriver-0.1.0-1.jar,  winium-elements-desktop-0.2.0-1.jar
  3. Create page object model for file upload and write TestNg script for file upload.

Here is project structure:

 

Note: Run Winium.Desktop.Driver.exe before executing script and allow public access on windows security alert.

File upload page object model implementation

TestNG Test script

TestNg Xml configuration file to execute script using TestNG Framework

 

This Article is TAGGED in , , . BOOKMARK THE permalink.

Neeraj Vishwakarma
Senior QA Engineer Skills: Automation Testing, Manual Testing, STLC, Java, Selenium Webdriver, Protractor, Database Testing.

Leave a Reply

Your email address will not be published. Required fields are marked *

4 + one =

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">