Could not upload file by UploadFile.uploadFileUsingRobot

I’m trying to upload a file using katalon-studio-uploadfile-plugin but unsuccessful.

The error as below was generate:
Reason: org.codehaus.groovy.runtime.typehandling.GroovyCastException: Cannot cast object 'com.kms.katalon.core.webui.driver.SmartWaitWebDriver@6f6a7463' with class 'com.kms.katalon.core.webui.driver.SmartWaitWebDriver' to class 'org.openqa.selenium.remote.RemoteWebDriver' at com.kms.katalon.keyword.uploadfile.UploadFile.uploadFileUsingRobot(UploadFile.groovy:41) at com.kms.katalon.keyword.uploadfile.UploadFile.invokeMethod(UploadFile.groovy) at com.kms.katalon.core.main.CustomKeywordDelegatingMetaClass.invokeStaticMethod( at Draft 3:18) at at com.kms.katalon.core.main.ScriptEngine.runScriptAsRawText( at com.kms.katalon.core.main.TestCaseExecutor.runScript( at com.kms.katalon.core.main.TestCaseExecutor.doExecute( at com.kms.katalon.core.main.TestCaseExecutor.processExecutionPhase( at com.kms.katalon.core.main.TestCaseExecutor.accessMainPhase( at com.kms.katalon.core.main.TestCaseExecutor.execute( at com.kms.katalon.core.main.TestCaseMain.runTestCase( at com.kms.katalon.core.main.TestCaseMain.runTestCase( at com.kms.katalon.core.main.TestCaseMain$runTestCase$ Source) at
Please help advise!

The object from which we can click to choose files:
<button type="button" class="btn btn-white btn--big">choose file to upload</button>

I searched this forum and found a mysterious conversation about “SmartAWaitWebDriver” between @ThanhTo and @Russ_Thomas.

But I have no input to the original issue.

Hi @vnduc74

The code of that plugin does not seem to be compatible, please create a custom keyword with the content from this original UploadFile class.

But replacing line 41 with

Capabilities caps = ((SmartWaitWebDriver) driver).getCapabilities()

Please try to see if that works. We will update the plugin.

1 Like

I’ve separated file upalod logic using Robot into separate class, and made methods static. In method fileAttachmentUsingRobot to pass path to image you want to be uploaded, i.e full system path to image.

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.awt.*;
import java.awt.datatransfer.StringSelection;
import java.awt.event.KeyEvent;

 * Created by ypolshchykau on 30.01.2015.
public class FileAttacherRobotImplementation {
    public final static Logger log = LoggerFactory.getLogger(FileAttacherRobotImplementation.class);

     * this method implements file attachment using Robot mechanism
     * @param filePathToImage

    public static void fileAttachmentUsingRobot(String filePathToImage) {
        Robot robot = null;
        try {
            robot = new Robot();
        } catch (AWTException e) {


     * method for copying file in order to attach file in File open window
     * @param str
    public static void setClipboardData(String str) {
        StringSelection stringSelection = new StringSelection(str);
        Toolkit.getDefaultToolkit().getSystemClipboard().setContents(stringSelection, null);


Hope this helps you.


Thanks all, this issue is fixed.
But seems that it doesn’t work when minimizing windows, we could not setClipboardData in this case. Have you any solutions for it?

This might work for you…