zoukankan      html  css  js  c++  java
  • selenium demo(四)

    Robot类处理方法

     1 package test;
     2 
     3 import java.awt.*;
     4 import java.awt.event.KeyEvent;
     5 import java.io.IOException;
     6 
     7 
     8 public class AutoTestFour {
     9 
    10 
    11         public static void pressKeyWithShift(Robot robot,int keyvalue){
    12             robot.keyPress(KeyEvent.VK_SHIFT);
    13             robot.keyPress(keyvalue);
    14             robot.keyRelease(keyvalue);
    15             robot.keyRelease(KeyEvent.VK_SHIFT);
    16         }
    17         public static  void  closeApplication(Robot robot){
    18             robot.keyPress(KeyEvent.VK_ALT);
    19             robot.keyPress(KeyEvent.VK_F4);
    20             robot.keyRelease(KeyEvent.VK_F4);
    21             robot.keyRelease(KeyEvent.VK_ALT);
    22         }
    23         public static void pressKey(Robot robot,int keyvalue){
    24             robot.keyPress(keyvalue);
    25             robot.keyRelease(keyvalue);
    26         }
    27         public static void main(String[] args) throws AWTException, IOException {
    28         try {
    29             Robot robot = new Robot();
    30             Runtime.getRuntime().exec("notepad");
    31             robot.delay(2000);
    32             for (int i = 0; i < 100; i++) {
    33                 pressKeyWithShift(robot, KeyEvent.VK_I);
    34                 pressKey(robot, KeyEvent.VK_SPACE);
    35                 pressKey(robot, KeyEvent.VK_A);
    36                 pressKey(robot, KeyEvent.VK_M);
    37                 pressKey(robot, KeyEvent.VK_SPACE);
    38                 pressKey(robot, KeyEvent.VK_T);
    39                 pressKey(robot, KeyEvent.VK_H);
    40                 pressKey(robot, KeyEvent.VK_E);
    41                 pressKey(robot, KeyEvent.VK_SPACE);
    42                 pressKeyWithShift(robot, KeyEvent.VK_J);
    43                 pressKey(robot, KeyEvent.VK_A);
    44                 pressKey(robot, KeyEvent.VK_V);
    45                 pressKey(robot, KeyEvent.VK_A);
    46                 pressKeyWithShift(robot, KeyEvent.VK_R);
    47                 pressKey(robot, KeyEvent.VK_O);
    48                 pressKey(robot, KeyEvent.VK_B);
    49                 pressKey(robot, KeyEvent.VK_O);
    50                 pressKey(robot, KeyEvent.VK_T);
    51                 pressKey(robot, KeyEvent.VK_ENTER);
    52             }
    53             closeApplication(robot);
    54         }
    55         catch (AWTException e){
    56             e.printStackTrace();
    57         }
    58     }
    59 }
  • 相关阅读:
    macOS Big Sur 关闭 SIP 正确方法
    绕过CDN寻找真实IP的8种方法
    mycat 链接mysql提示ERROR 3009 (HY000): java.lang.IllegalArgumentExceptio解决方式
    【SpringBoot】SpringBoot 内嵌容器及性能
    【Java】基于NIO的聊天室
    【Java】基于BIO的聊天室
    【ZooKeeper】ZooKeeper源码编译
    【SpringBoot】 使用外部Tomcat方法及启动原理
    【Java】深入理解SPI机制
    【SpringBoot】SpringBoot 自动配置原理
  • 原文地址:https://www.cnblogs.com/drnmmond/p/7474425.html
Copyright © 2011-2022 走看看