# How to Upload a file from windows explorer

**URL:** <https://forum.katalon.com/t/how-to-upload-a-file-from-windows-explorer/6011>\
**Category:** Miscellaneous\
**Tags:** katalon-studio\
**Created:** [June 12, 2017, 12:33pm UTC](https://forum.katalon.com/t/how-to-upload-a-file-from-windows-explorer/6011 "2017-06-12T12:33:09Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Srinivasan\_S](https://avatars.discourse-cdn.com/v4/letter/s/eb9ed0/32.png) [@Srinivasan\_S](https://forum.katalon.com/u/Srinivasan_S)\
**Post date:** [June 12, 2017, 12:33pm UTC](https://forum.katalon.com/t/how-to-upload-a-file-from-windows-explorer/6011/1 "2017-06-12T12:33:09Z")

</div>

Hi,

in my project , i can able to click on a button to upload after that i cannot able to select a a file from the windows explorer path to upload. please help me with an example

---

<div class="post-metadata">

**Author:** ![Mallika](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/mallika/32/23870_2.png) [@Mallika](https://forum.katalon.com/u/Mallika)\
**Post date:** [June 22, 2017, 7:08am UTC](https://forum.katalon.com/t/how-to-upload-a-file-from-windows-explorer/6011/2 "2017-06-22T07:08:55Z")

</div>

Use this below code:Simple just load the upload object with the file which you placed in the local system.  
Like load the object with you local file path.  
WebUI.uploadFile(findTestObject(‘ASACoverObjs/ChooseDocFileBtnObj’), “F:\\AutomationProjects\\BeautyBookingWebSite\\BeautyBookingWebsiteAutomationProject21042017\\Data Files\\TestDataFiles\\Test Data Doc file.docx”)

---

<div class="post-metadata">

**Author:** ![duyluong](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/duyluong/32/1116_2.png) [@duyluong](https://forum.katalon.com/u/duyluong)\
**Post date:** [June 13, 2017, 3:44am UTC](https://forum.katalon.com/t/how-to-upload-a-file-from-windows-explorer/6011/3 "2017-06-13T03:44:01Z")

</div>

The UploadFile keyword only works if your field is **.** Please check again. If it isn’t, please use this keyword.

`import java.awt.Robot`  
`import java.awt.Toolkit`  
`import java.awt.datatransfer.StringSelection`  
`import java.awt.event.KeyEvent`

`import com.kms.katalon.core.testobject.TestObject`  
`import com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords as WebUI`

`def uploadFile(TestObject to, String filePath) {`

`WebUI.click(to)`

`StringSelection ss = new StringSelection(filePath);`  
`Toolkit.getDefaultToolkit().getSystemClipboard().setContents(ss, null);`

`Robot robot = new Robot();`  
`robot.keyPress(KeyEvent.VK_ENTER);`  
`robot.keyRelease(KeyEvent.VK_ENTER);`  
`robot.keyPress(KeyEvent.VK_CONTROL);`  
`robot.keyPress(KeyEvent.VK_V);`  
`robot.keyRelease(KeyEvent.VK_V);`  
`robot.keyRelease(KeyEvent.VK_CONTROL);`  
`robot.keyPress(KeyEvent.VK_ENTER);`  
`robot.keyRelease(KeyEvent.VK_ENTER);`  
`}`

---

<div class="post-metadata">

**Author:** ![Hanh\_Tran](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/hanh_tran/32/651_2.png) [@Hanh\_Tran](https://forum.katalon.com/u/Hanh_Tran)\
**Post date:** [June 13, 2017, 3:14am UTC](https://forum.katalon.com/t/how-to-upload-a-file-from-windows-explorer/6011/4 "2017-06-13T03:14:18Z")

</div>

That keyword will:

1. Click on ‘Upload’ button on the web application

2. Select the file based on the input path to that keyword.

That’s all for how of this keyword behaves.

Can you please tell me more about why it didn’t work from your side after you’ve tried it?

---

<div class="post-metadata">

**Author:** ![Srinivasan\_S](https://avatars.discourse-cdn.com/v4/letter/s/eb9ed0/32.png) [@Srinivasan\_S](https://forum.katalon.com/u/Srinivasan_S)\
**Post date:** [June 12, 2017, 1:00pm UTC](https://forum.katalon.com/t/how-to-upload-a-file-from-windows-explorer/6011/5 "2017-06-12T13:00:52Z")

</div>

Actually this didnt work. Moreover it does not have an image to understand how this works.

Once the attachment button is clicked it navigates to windows explorer to choose the file but we are not sure how to go after that.

whether we need to find any other way or any integartion is required like auto it to support this upload feature?

---

<div class="post-metadata">

**Author:** ![Hanh\_Tran](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/hanh_tran/32/651_2.png) [@Hanh\_Tran](https://forum.katalon.com/u/Hanh_Tran)\
**Post date:** [June 12, 2017, 12:39pm UTC](https://forum.katalon.com/t/how-to-upload-a-file-from-windows-explorer/6011/6 "2017-06-12T12:39:54Z")

</div>

Please use ‘[Upload File](https://docs.katalon.com/display/KD/%5BWebUI%5D+Upload+File)’ keyword. Example is within that page.

---

<div class="post-metadata">

**Author:** ![Wei\_Luo](https://avatars.discourse-cdn.com/v4/letter/w/e56c9b/32.png) [@Wei\_Luo](https://forum.katalon.com/u/Wei_Luo)\
**Post date:** [March 29, 2018, 7:18pm UTC](https://forum.katalon.com/t/how-to-upload-a-file-from-windows-explorer/6011/7 "2018-03-29T19:18:57Z")

</div>

> duyluong said:
> 
> The UploadFile keyword only works if your field is **.** Please check again. If it isn’t, please use this keyword.
> 
> `import java.awt.Robot`  
> `import java.awt.Toolkit`  
> `import java.awt.datatransfer.StringSelection`  
> `import java.awt.event.KeyEvent`
> 
> `import com.kms.katalon.core.testobject.TestObject`  
> `import com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords as WebUI`
> 
> `def uploadFile(TestObject to, String filePath) {`
> 
> `WebUI.click(to)`
> 
> `StringSelection ss = new StringSelection(filePath);`  
> `Toolkit.getDefaultToolkit().getSystemClipboard().setContents(ss, null);`
> 
> `Robot robot = new Robot();`  
> `robot.keyPress(KeyEvent.VK_ENTER);`  
> `robot.keyRelease(KeyEvent.VK_ENTER);`  
> `robot.keyPress(KeyEvent.VK_CONTROL);`  
> `robot.keyPress(KeyEvent.VK_V);`  
> `robot.keyRelease(KeyEvent.VK_V);`  
> `robot.keyRelease(KeyEvent.VK_CONTROL);`  
> `robot.keyPress(KeyEvent.VK_ENTER);`  
> `robot.keyRelease(KeyEvent.VK_ENTER);`  
> `}`

How to use this keyword in the script of test case? insert into which place? Do I need to revise any words in the above script? please state clearly. it would be more helpful if you attach some files to illustrate it.  
upload file key word is not working in my test case.

---

<div class="post-metadata">

**Author:** ![Vijay2](https://avatars.discourse-cdn.com/v4/letter/v/f6c823/32.png) [@Vijay2](https://forum.katalon.com/u/Vijay2)\
**Post date:** [May 25, 2018, 6:34pm UTC](https://forum.katalon.com/t/how-to-upload-a-file-from-windows-explorer/6011/8 "2018-05-25T18:34:43Z")

</div>

> Wei Luo said:
> 
> > duyluong said:
> > 
> > The UploadFile keyword only works if your field is **.** Please check again. If it isn’t, please use this keyword.
> > 
> > `import java.awt.Robot`  
> > `import java.awt.Toolkit`  
> > `import java.awt.datatransfer.StringSelection`  
> > `import java.awt.event.KeyEvent`
> > 
> > `import com.kms.katalon.core.testobject.TestObject`  
> > `import com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords as WebUI`
> > 
> > `def uploadFile(TestObject to, String filePath) {`
> > 
> > `WebUI.click(to)`
> > 
> > `StringSelection ss = new StringSelection(filePath);`  
> > `Toolkit.getDefaultToolkit().getSystemClipboard().setContents(ss, null);`
> > 
> > `Robot robot = new Robot();`  
> > `robot.keyPress(KeyEvent.VK_ENTER);`  
> > `robot.keyRelease(KeyEvent.VK_ENTER);`  
> > `robot.keyPress(KeyEvent.VK_CONTROL);`  
> > `robot.keyPress(KeyEvent.VK_V);`  
> > `robot.keyRelease(KeyEvent.VK_V);`  
> > `robot.keyRelease(KeyEvent.VK_CONTROL);`  
> > `robot.keyPress(KeyEvent.VK_ENTER);`  
> > `robot.keyRelease(KeyEvent.VK_ENTER);`  
> > `}`
> 
> How to use this keyword in the script of test case? insert into which place? Do I need to revise any words in the above script? please state clearly. it would be more helpful if you attach some files to illustrate it.  
> upload file key word is not working in my test case.

Wei,

You have to create a new Keyword by right click on Keywords \> New \> Keyword

if there is Keyword already exists just double click on it and add @Keyword on the top of def uploadFile(TestObject to, String filepath)

```auto
@Keyword 
def uploadFile(TestObject to, String filePath) {
WebUI.click(to)

StringSelection ss = new StringSelection(filePath);
Toolkit.getDefaultToolkit().getSystemClipboard().setContents(ss, null);

Robot robot = new Robot();
robot.keyPress(KeyEvent.VK_ENTER);
robot.keyRelease(KeyEvent.VK_ENTER);
robot.keyPress(KeyEvent.VK_CONTROL);
robot.keyPress(KeyEvent.VK_V);
robot.keyRelease(KeyEvent.VK_V);
robot.keyRelease(KeyEvent.VK_CONTROL);
robot.keyPress(KeyEvent.VK_ENTER);
robot.keyRelease(KeyEvent.VK_ENTER);
}

```
