# How to Interact with File Upload Window

**URL:** <https://forum.katalon.com/t/how-to-interact-with-file-upload-window/6338>\
**Category:** Web Testing\
**Tags:** katalon-studio\
**Created:** [August 4, 2017, 2:14am UTC](https://forum.katalon.com/t/how-to-interact-with-file-upload-window/6338 "2017-08-04T02:14:31Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![numaroth021](https://avatars.discourse-cdn.com/v4/letter/n/7c8e57/32.png) [@numaroth021](https://forum.katalon.com/u/numaroth021)\
**Post date:** [August 4, 2017, 2:14am UTC](https://forum.katalon.com/t/how-to-interact-with-file-upload-window/6338/1 "2017-08-04T02:14:31Z")

</div>

Hi,

I\'m trying to automate file attachment / file upload to gmail. While the rest of automation is working, the popup window to select file that needed to upload is not working. I already went through some file upload guide but still cannot get it done.

Please see this screenshot: [1 — ImgBB](http://ibb.co/dqUYUv)

It works until step number 2. But then failed to select the file on step number 3.

Kindly please help

---

<div class="post-metadata">

**Author:** ![Zarashima](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/zarashima/32/928_2.png) [@Zarashima](https://forum.katalon.com/u/Zarashima)\
**Post date:** [August 4, 2017, 3:46am UTC](https://forum.katalon.com/t/how-to-interact-with-file-upload-window/6338/2 "2017-08-04T03:46:11Z")

</div>

We can’t access your link. Can you upload your screenshot again to other page such as [https://prnt.sc/](https://prnt.sc/)?

---

<div class="post-metadata">

**Author:** ![dan\_robitialle](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/dan_robitialle/32/23869_2.png) [@dan\_robitialle](https://forum.katalon.com/u/dan_robitialle)\
**Post date:** [October 23, 2017, 5:31pm UTC](https://forum.katalon.com/t/how-to-interact-with-file-upload-window/6338/3 "2017-10-23T17:31:01Z")

</div>

I use the Set text |imput\_filename | path\nameoffile.doc  
The script looks like this  
WebUI.setText(findTestObject(‘Page\_Edit Business Card/input\_FileName’), ‘U:\Resume of a Tester.doc’)  
I had an issue finding the input object as Katalon didn’t record it directly, I end up using Spyweb to find it.

---

<div class="post-metadata">

**Author:** ![manish\_shriwastwa](https://avatars.discourse-cdn.com/v4/letter/m/87869e/32.png) [@manish\_shriwastwa](https://forum.katalon.com/u/manish_shriwastwa)\
**Post date:** [January 18, 2018, 5:44pm UTC](https://forum.katalon.com/t/how-to-interact-with-file-upload-window/6338/4 "2018-01-18T17:44:23Z")

</div>

WebUI.setText(findTestObject(‘Page\_Edit Business Card/input\_FileName’), ‘U:\Resume of a Tester.doc’)

you can try by specifying the xpath as “//input[@type=‘file’]” in the “ **input\_FileName** ” test object.  
or alternatively create a custom object and specify the xpath as “//input[@type=‘file’]”

---

<div class="post-metadata">

**Author:** ![plaidshirtakos](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/plaidshirtakos/32/9361_2.png) [@plaidshirtakos](https://forum.katalon.com/u/plaidshirtakos)\
**Post date:** [September 4, 2018, 6:11am UTC](https://forum.katalon.com/t/how-to-interact-with-file-upload-window/6338/5 "2018-09-04T06:11:08Z")

</div>

You can try also AutoIT scripting: [https://www.autoitscript.com/site/autoit/](https://www.autoitscript.com/site/autoit/)

---

<div class="post-metadata">

**Author:** ![emine](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/emine/32/15639_2.png) [@emine](https://forum.katalon.com/u/emine)\
**Post date:** [February 7, 2019, 10:45am UTC](https://forum.katalon.com/t/how-to-interact-with-file-upload-window/6338/6 "2019-02-07T10:45:28Z")

</div>

Hello ,  
You can follow these steps for this situation.  
1-You must create a new custom keyword. You can access the link below for new add Custom Keyword .  
[https://docs.katalon.com/katalon-studio/tutorials/create\_custom\_keyword.html](https://docs.katalon.com/katalon-studio/tutorials/create_custom_keyword.html)

2-You must add the following snippet in Keyword.  
import com.kms.katalon.core.annotation.Keyword  
import com.kms.katalon.core.testobject.TestObject  
import com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords as WebUI  
import internal.GlobalVariable

public class testclass {

```
@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);
}

```

}

3-Finally, you should call keyword u in the corresponding step.  
After the keyword is included in the project, the relevant test case step in the script field should be as follows.  
CustomKeywords.‘test.testclass.uploadFile’(findTestObject(‘Test\_uploadfile\_field’), 'C:\Users\\Desktop\test data)

Hopefully it is helpful.

---

<div class="post-metadata">

**Author:** ![tracy\_campo09](https://avatars.discourse-cdn.com/v4/letter/t/f0a364/32.png) [@tracy\_campo09](https://forum.katalon.com/u/tracy_campo09)\
**Post date:** [July 2, 2020, 2:58am UTC](https://forum.katalon.com/t/how-to-interact-with-file-upload-window/6338/7 "2020-07-02T02:58:15Z")

</div>

It works for me. However, if I used custom keyword again in the same test case, it’s not working in the 2nd object.

Here’s my script

 ![Screenshot_2](https://europe1.discourse-cdn.com/katalon/original/2X/e/e615fc4c9d98e3cb9c02983c15f5f9473e25240a.jpeg) ![script](https://europe1.discourse-cdn.com/katalon/original/2X/e/e461346627f691d1e5c6370b65c7b4195457751a.jpeg)

---

<div class="post-metadata">

**Author:** ![albert.vu](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/albert.vu/32/20595_2.png) [@albert.vu](https://forum.katalon.com/u/albert.vu)\
**Post date:** [August 8, 2022, 7:31am UTC](https://forum.katalon.com/t/how-to-interact-with-file-upload-window/6338/8 "2022-08-08T07:31:58Z")

</div>

Archived on August 8, 2022, 7:31am UTC


