我有一个键盘事件代码,但是此代码在mac os High Sierra版本10.13.4上不起作用。
只能听到蜂鸣声且未执行键盘操作
WebDriver driver = new ChromeDriver();
driver.get("http://newtours.demoaut.com/");
Actions mouse = new Actions(driver);
WebElement Register = driver.findElement(By.linkText("REGISTER"));
mouse.contextClick(Register).build().perform();
Thread.sleep(2000);
try {
Robot robot = new Robot();
for(int i=0;i<2;i++) {
robot.keyPress(KeyEvent.VK_DOWN);
robot.keyRelease(KeyEvent.VK_DOWN);
Thread.sleep(2000);
}
robot.keyPress(KeyEvent.VK_ENTER);
robot.keyRelease(KeyEvent.VK_ENTER);
}