How to send keyboard shortcut ALT SHIFT z (hotkey)

2019-01-22 22:43发布

问题:

I am trying send shortcut with Actions.sendKeys, but it isn't work.

(New Actions(driver)).SendKeys(Keys.ALT, Keys.SHIFT, "z");

回答1:

You can check this question to refer about this - Key press in (Ctrl+A) Selenium WebDriver

Check the answer which uses the chord method, in your case you can do this -

String selectAll = Keys.chord(Keys.ALT, Keys.SHIFT,"z");
driver.findElement(By.tagName("html")).sendKeys(selectAll);


回答2:

This can also be done using Actions keyUp and keyDown funcitons.

WebDriver driver = new FirefoxDriver();
Actions keyAction = new Actions(driver);     
keyAction.keyDown(Keys.ALT).keyDown(Keys.SHIFT).sendKeys("z").keyUp(Keys.ALT).keyUp(Keys.SHIFT).perform();


回答3:

Try it:

SendKeys.SendWait("%+z")