Unable to import files with Robot due to issues with access to the clipboard when Windows is locked

Hello,

I have some test cases that I would like to run overnight because they are taking a pretty long time. I have some test cases in which I have to import files.

I use Robot library which is mentioned here to import files. Importing files perfectly works when Windows is not locked. However, my test cases containing file imports are failing when my computer is locked. I have to lock my computer at night due to company security policies. Please see the error on the console below.

According to the error message, Katalon is not able to access the clipboard when Windows is locked. Because the file path is copied to the clipboard when importing through Robot library, Katalon needs to access the clipboard but because Windows does not give access to the clipboard, importing files fails.

I tried using “WebUiBuiltInKeywords.uploadFile(object, file)” to import files but it looks like this is not working even when the computer is not locked.

Do you guys have any suggestions to solve this issue?

Thank you very much in advance,

Test Cases/Estimates/TC_ImportDiagram FAILED. Reason: java.lang.IllegalStateException: cannot open system clipboard at ABCCORP.ImportFiles.uploadFile(ImportFiles.groovy:19) at ABCCORP.ImportFiles.invokeMethod(ImportFiles.groovy) at com.kms.katalon.core.main.CustomKeywordDelegatingMetaClass.invokeStaticMethod(CustomKeywordDelegatingMetaClass.java:50) at TC_ImportDiagram.run(TC_ImportDiagram:28) at com.kms.katalon.core.main.ScriptEngine.run(ScriptEngine.java:194) at com.kms.katalon.core.main.ScriptEngine.runScriptAsRawText(ScriptEngine.java:119) at com.kms.katalon.core.main.TestCaseExecutor.runScript(TestCaseExecutor.java:337) at com.kms.katalon.core.main.TestCaseExecutor.doExecute(TestCaseExecutor.java:328) at com.kms.katalon.core.main.TestCaseExecutor.processExecutionPhase(TestCaseExecutor.java:307) at com.kms.katalon.core.main.TestCaseExecutor.accessMainPhase(TestCaseExecutor.java:299) at com.kms.katalon.core.main.TestCaseExecutor.execute(TestCaseExecutor.java:233) at com.kms.katalon.core.main.TestCaseMain.runTestCase(TestCaseMain.java:114) at com.kms.katalon.core.main.TestCaseMain.runTestCase(TestCaseMain.java:105) at com.kms.katalon.core.main.TestCaseMain$runTestCase$0.call(Unknown Source) at TempTestCase1581542190007.run(TempTestCase1581542190007.groovy:23)

@minan You can try to send the path directly to the Textbox with sendKeys(path), and not select the file over the selector at all.

1 Like

@Jens.gr Thank you for your suggestion. Unfortunately, I do not have a text box to send keys on the page. Please check the screenshot. I have a link to open File Upload window.

“Drag and Drop” functionality is also available on the page so I can go with any of these two options to upload a file if you have any suggestions related to these two options.

Thank you

Can you show the inspector of that drag and drop element. as usual it must have some kind of input field behind like:

And to that you could send the path to the file with send keys directly.

1 Like

I think it is this one:

<input _ngcontent-ehp-c66="" aria-hidden="true" class="hidden-call-to-action" flow-btn="" hidden="" type="file" accept="text/xml" multiple="">

How can I use it to import files?

Thank you,

That looks like the right field.

You get that element as a WebElement (Xpath / JS Selector or any kind that works for you) and use the sendKeys with the path in it to upload your file. We use a Keyword like this… with JsPath selection

@Keyword
	def UploadFile(java.lang.String path, java.lang.String filePathUnderDataFiles)
	{
		try
		{

			WebDriver driver = DriverFactory.getWebDriver()
			path = "return "+path

Change the selector wto what ever you like so your getting the element

			WebElement ele = (WebElement) ((JavascriptExecutor)driver).executeScript(path)
			ele.sendKeys(filePathUnderDataFiles);
			KeywordUtil.markPassed("Uploaded file to element")
		}
		catch(Exception e)
		{
			KeywordUtil.markFailed("Could not upload file to element")
		}
		return null
	}

Hope it helps :slight_smile:

1 Like

Thank you very much @Jens.gr for your help.
It worked.