Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Copy paste not working using Robot Class: Ctrl+C; content is not saving into clipboard, but it used to work perfectly fine few days back #5327

Closed
praveenreddygm opened this issue Jan 11, 2018 · 7 comments

Comments

@praveenreddygm
Copy link

Meta -

OS: Windows 10
Selenium Version: 3.5.3; WebDriver
Browser: NA; Trying to copy text from outlook/Any file using Robot class and its features; Basically we can open outlook using Sikuli or Winnium; here problem is about Robot class and its features that "Using Robot class i have copied content during run time BCDE and trying to retrieve it from clipboard to print again in console or any other file. But it's fetching old value from the clip board? but it used to work perfectly fine few days back.
Expected Output is: BCDE"

import java.awt.AWTException;
import java.awt.HeadlessException;
import java.awt.Robot;
import java.awt.Toolkit;
import java.awt.datatransfer.Clipboard;
import java.awt.datatransfer.DataFlavor;
import java.awt.datatransfer.StringSelection;
import java.awt.datatransfer.Transferable;
import java.awt.datatransfer.UnsupportedFlavorException;
import java.awt.event.InputEvent;
import java.awt.event.KeyEvent;
import java.io.IOException;

import org.sikuli.basics.Settings;
import org.sikuli.script.FindFailed;
import org.sikuli.script.Key;
import org.sikuli.script.Pattern;
import org.sikuli.script.Screen;

public class Sikuli_Demo {

public static void main(String[] args) throws InterruptedException, FindFailed, AWTException, HeadlessException, UnsupportedFlavorException, IOException {

Screen screen=new Screen();
Thread.sleep(2000);
Pattern clickOutlook=new Pattern("images\\1_ClickOutlook.png");

Pattern clickNewMail=new Pattern("images\\3_NewMail.png");

screen.click(clickOutlook);
Thread.sleep(2000);
screen.click(clickNewMail);
Thread.sleep(2000);
screen.type("ABCDE");
screen.type(Key.LEFT+Key.LEFT+Key.LEFT+Key.LEFT);
Thread.sleep(2000);

Robot robot=new Robot();
Thread.sleep(4000);

robot.keyPress(KeyEvent.VK_SHIFT);
robot.keyPress(KeyEvent.VK_RIGHT);
robot.keyPress(KeyEvent.VK_SHIFT);
robot.keyPress(KeyEvent.VK_RIGHT);
robot.keyPress(KeyEvent.VK_SHIFT);
robot.keyPress(KeyEvent.VK_RIGHT);
robot.keyPress(KeyEvent.VK_SHIFT);
robot.keyPress(KeyEvent.VK_RIGHT);

Thread.sleep(2000);
robot.keyRelease(KeyEvent.VK_RIGHT);
robot.keyRelease(KeyEvent.VK_SHIFT);
Thread.sleep(2000);
System.out.println("Check1");
robot.keyPress(KeyEvent.VK_CONTROL);
robot.keyPress(KeyEvent.VK_C);
Thread.sleep(2000);
robot.keyRelease(KeyEvent.VK_CONTROL);
robot.keyRelease(KeyEvent.VK_C);
Thread.sleep(2000);
robot.keyPress(KeyEvent.VK_RIGHT);
robot.keyRelease(KeyEvent.VK_RIGHT);

System.out.println("Check2");

String str=(String)Toolkit.getDefaultToolkit().getSystemClipboard().getData(DataFlavor.stringFlavor);
Thread.sleep(2000);

System.out.println("Copied content is :"+str);
screen.type(str);

}
}

**Console:
1_clickoutlook
3_newmail

**
Basically i got below error first:
Jan 11, 2018 6:15:36 PM java.util.prefs.WindowsPreferences
WARNING: Could not open/create prefs root node Software\JavaSoft\Prefs at root 0x80000002. Windows RegCreateKeyEx(...) returned error code 5.
[log] CLICK on L(540,1401)@s(0)[0,0 2560x1440]
[log] CLICK on L(58,214)@s(0)[0,0 2560x1440]
[log] TYPE "ABCDE"
[log] TYPE "#LEFT.#LEFT.#LEFT.#LEFT."
Check1
Check2
Exception in thread "main" java.awt.datatransfer.UnsupportedFlavorException: Unicode String
at sun.awt.datatransfer.SunClipboard.getData(Unknown Source)
at Sikuli_Demo.main(Sikuli_Demo.java:63)

But After following below steps error is not coming but clipboard is not saving the copied content during run time: https://stackoverflow.com/questions/8513740/copy-paste-not-working-in-a-signed-applet

On Windows 7, it can be found at C:\Program Files (x86)\Java\jre6\lib\security. Copy this file to your home folder (ex. C:\Users\Kyle). Rename the file to .java.policy (note the period at the beginning). Edit the file in a text editor. Locate this line of text:
Add the following line just below it like so:

// "standard" properies that can be read by anyone
permission java.awt.AWTPermission "accessClipboard";
Save the file. Close any open browsers and ensure that Java is not running before testing.

Console after following above steps:

Jan 11, 2018 5:41:31 PM java.util.prefs.WindowsPreferences
WARNING: Could not open/create prefs root node Software\JavaSoft\Prefs at root 0x80000002. Windows RegCreateKeyEx(...) returned error code 5.
[log] CLICK on L(540,1401)@s(0)[0,0 2560x1440]
[log] CLICK on L(58,214)@s(0)[0,0 2560x1440]
[log] TYPE "ABCDE"
[log] TYPE "#LEFT.#LEFT.#LEFT.#LEFT."
Check1
Check2
Copied content is :praveenreddygm@gmail.com
[log] TYPE "praveenreddygm@gmail.com "

Expected Output: BCDE

@barancev
Copy link
Member

Not related to Selenium.

@praveenreddygm
Copy link
Author

May i know which is the right platform? Below statement is the issue, i believe its part of selenium-Robot (import java.awt.*)
String str=(String)Toolkit.getDefaultToolkit().getSystemClipboard().getData(DataFlavor.stringFlavor);

Error: Exception in thread "main" java.awt.datatransfer.UnsupportedFlavorException: Unicode String
at sun.awt.datatransfer.SunClipboard.getData(Unknown Source)

@praveenreddygm
Copy link
Author

I mean its copying text and not storing text into clipboard using robot class Key Events, but it used to working fine previously

robot.keyPress(KeyEvent.VK_SHIFT);
robot.keyPress(KeyEvent.VK_RIGHT);
robot.keyPress(KeyEvent.VK_SHIFT);
robot.keyPress(KeyEvent.VK_RIGHT);
robot.keyPress(KeyEvent.VK_SHIFT);
robot.keyPress(KeyEvent.VK_RIGHT);
robot.keyPress(KeyEvent.VK_SHIFT);
robot.keyPress(KeyEvent.VK_RIGHT);

Thread.sleep(2000);
robot.keyRelease(KeyEvent.VK_RIGHT);
robot.keyRelease(KeyEvent.VK_SHIFT);
Thread.sleep(2000);
robot.keyPress(KeyEvent.VK_CONTROL);
robot.keyPress(KeyEvent.VK_C);
Thread.sleep(2000);
robot.keyRelease(KeyEvent.VK_CONTROL);
robot.keyRelease(KeyEvent.VK_C);
Thread.sleep(2000);
robot.keyPress(KeyEvent.VK_RIGHT);
robot.keyRelease(KeyEvent.VK_RIGHT);

String str=(String)Toolkit.getDefaultToolkit().getSystemClipboard().getData(DataFlavor.stringFlavor);

@lmtierney
Copy link
Member

If you think there's an issue with selenium, offer a reproducible scenario using only selenium. Otherwise, I'm afraid it's impossible for us to debug. Please raise an issue with the library you are using first. If something "just changed" within the last couple of days, if anything it is probably a driver issue and not a selenium issue.

@barancev
Copy link
Member

Java AWT Robot is a part of Java SDK, it's not a part of Selenium.

@praveenreddygm
Copy link
Author

@barancev Could you please help me with exact link where i can raise this issue. I'm not able to find it out. Thanks in Advance !!

@barancev
Copy link
Member

This is a question rather than an issue. Try to post it to https://stackoverflow.com/

@lock lock bot locked and limited conversation to collaborators Aug 16, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants