我尝试通过不同的代码打开Wave工具扩展,但它不起作用。以下是我尝试过的所有东西:
Robot rb=new Robot();
选项1:
rb.keyPress(KeyEvent.VK_CONTROL);
rb.delay(100);
rb.keyPress(KeyEvent.VK_SHIFT);
rb.delay(100);
rb.keyPress(KeyEvent.VK_U);`
//close
rb.delay(100);
rb.keyRelease(KeyEvent.VK_U);
rb.delay(100);
rb.keyRelease(KeyEvent.VK_SHIFT);
rb.delay(100);
rb.keyRelease(KeyEvent.VK_CONTROL);
选项2:
action.keyDown(Keys.CONTROL).keyDown(Keys.SHIFT).sendKeys("u").keyUp(Keys.CONTROL).keyUp(Keys.SHIFT).perform();
早些时候,我用"右键单击"过程打开它
`
action.contextClick().build().perform();
Thread.sleep(500);
robot.keyPress(KeyEvent.VK_DOWN);
Thread.sleep(500);
robot.keyPress(KeyEvent.VK_DOWN);
Thread.sleep(500);
robot.keyPress(KeyEvent.VK_DOWN);
Thread.sleep(500);
robot.keyPress(KeyEvent.VK_DOWN);
Thread.sleep(500);
robot.keyPress(KeyEvent.VK_DOWN);
Thread.sleep(500);
robot.keyPress(KeyEvent.VK_DOWN);
Thread.sleep(500);
robot.keyPress(KeyEvent.VK_DOWN);
Thread.sleep(500);
robot.keyPress(KeyEvent.VK_ENTER);
`
但现在我正在尝试切换到快捷键(CONTROL+SHIFT+U(。有人能帮我吗。在Chrome上尝试过这个。
找到了解决方案。这不合适,但对我来说是可行的。我们可以直接打开扩展快捷窗口,分配快捷键(我已经分配了"CONTROL+I"(,导航到我们的网站,并使用robot类打开"WAVE工具"。
// setup key shourtcut for extension
driver.navigate().to("chrome://extensions/shortcuts");
Thread.sleep(1000);
robot.keyPress(KeyEvent.VK_TAB);
robot.keyPress(KeyEvent.VK_TAB);
robot.keyPress(KeyEvent.VK_CONTROL);
robot.keyPress(KeyEvent.VK_I);
robot.keyRelease(KeyEvent.VK_I);
robot.keyRelease(KeyEvent.VK_CONTROL);
希望这能帮助其他人。