HeadlessException while reading Clipboard

groovy
rpaexpress

#1

Hello,
I’m trying to read clipboard content using:

Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard()
String result = clipboard.getContents(null).getTransferData(DataFlavor.stringFlavor)

In SPA Sudio it works good but in RPAExpress I get java.awt.HeadlessException. Do you know some way to fix it in RPAStudio?


#2

@pawel_faron,

Why don’t you use the simplified API?

clipboardText()

#3

Hi @pawel_faron

I faced the same issue . You are using Clipboard which is a part of AWT package.
if you want to use this you need to call it from out side the from

import java.nio.file.Paths; import java.awt.datatransfer.StringSelection; import java.awt.Toolkit; import java.awt.datatransfer.Clipboard; String your_varaiable=Paths.get("%s"); StringSelection selection = new StringSelection(your_varaiable); Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard(); clipboard.setContents(selection, selection)

and call it in selenium or robotics-flow

using.

clip =String.format(clipboard.toString(),your_varable.toString());
sDriver.executeScript(clip.toString(), “GROOVY”);


#4

The only reason is that I didn’t know it :wink: Works, thanks.


#5

see https://kb.workfusion.com/display/RPA/Simplified+Robotics+API


#6

Hi,

I am trying to copy content from a web page without Xpath.
I want to use CTRL + A , CTRL+ C and the copy the clipboard content to variable.

For that I have used -

class ClipboardUtils{
    static final Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
    static void setClipboardContents(final String contents){
        clipboard.setContents(new StringSelection(contents), null)
    }

static String getClipboardContents(){
    return clipboard.getContents(null).getTransferData(DataFlavor.stringFlavor)
}
}


  <robotics-flow>
		<robot name="seleniumDriver" driver="chrome"
			close-on-completion="true" start-in-private="false">
			
			<script><![CDATA[
				
			driver= seleniumDriver.getWrappedObject();
     		      driver.get(Lname.toString());
	              Thread.sleep(5000);    
	                 element= driver.findElement(By.xpath("//body"));    
		            element.sendKeys(Keys.CONTROL + "a");
                     element.sendKeys(Keys.CONTROL + "c");
                     Thread.sleep(5000);                  
                    HtmlText=ClipboardUtils.getClipboardContents().toString();
	
			]]></script>
    </robot>
	</robotics-flow>

Getting same Error java.awt.HeadlessException on RPA express server.

I am not able to understand the solution giving in here.

I tried using clipboardText() . but it gives error
Current Selenium driver ‘chrome’ is not Desktop driver, but is expected for requested action. Invoked action is not supported by this driver yet.

As I am using chrome not a desktop driver.

Could you please help how to used clipboard on web browser.

Thanks


#7

@tilak_patil,

you need to create another <robot> plugin with driver=“desktop”

and then execute def htmlText = clipboardText() inside this <robot> plugin

See some similar examples here:
https://kb.workfusion.com/display/RPA/Automating+File+Upload
https://kb.workfusion.com/display/RPA/Handling+File+Download


#8

Hi,
Thanks for your reply.
the suggested solution worked.

<robotics-flow>
<robot name="seleniumDriver" driver="chrome"
			close-on-completion="false" start-in-private="false">
<script>
    <![CDATA[
				  driver= seleniumDriver.getWrappedObject();
 			      driver.get(Lname.toString());
			      Thread.sleep(5000);
			      element= driver.findElement(By.xpath("//body"));
		          element.sendKeys(Keys.CONTROL + "a");
              element.sendKeys(Keys.CONTROL + "c");
 </robot>
 <robot name="desktopDriver" driver="desktop" close-on-completion="false"><script>
    <![CDATA[
           switchTo().window('[CLASS:Intermediate D3D Window; INSTANCE:1]');
            HtmlText = clipboardText() ;
            
        ]]>
</script>
</robot>

#9

@tilak_patil - you might wamt to use the universal driver which is more convenient for such cases:

https://kb.workfusion.com/display/RPA/Universal+RPA+Driver

https://kb.workfusion.com/display/RPA/Automating+File+Upload#AutomatingFileUpload-universal

And using Simplified Robotics API - https://kb.workfusion.com/display/RPA/Simplified+Robotics+API