Selenium学习14--KeyBoardUtil

来源:互联网 发布:怎么虚拟mac地址 编辑:程序博客网 时间:2024/06/05 07:21

封装键盘操作的工具类

public class KeyBoardUtil{    //press Tab key    public static void pressTabKey(){        Robot robot = null;        try{                robot = new Robot();            }catch(Exception e){                e.printStackTrace();            }            robot.KeyPress(KeyEvent.VK_TAB);            robot.KeyRelease(KeyEvent.VK_TAB);    }    //press Enter key    public static void pressEnterKey(){        Robot robot = null;        try{                robot = new Robot();            }catch(Exception e){                e.printStackTrace();            }            robot.KeyPress(KeyEvent.VK_ENTER);            robot.KeyRelease(KeyEvent.VK_ENTER);    }    //将字符串设为剪切板内容,执行黏贴操作    public static void setAndCtrlVClicpboardData(String string){        StringSelection stringSelection = new StringSeleection(string);        ToolKit.getDefaultToolkit().getSystemClipboard().setContents(stringSelection,null);        Robot robot = null;        try{                robot = new Robot();            }catch(Exception e){                e.printStackTrace();            }            robot.KeyPress(KeyEvent.VK_CONTROL);            robot.KeyPress(KeyEvent.VK_V);            robot.KeyRelease(KeyEvent.VK_CONTROL);            robot.KeyRelease(KeyEvent.VK_V);    }}
0 0