How to send keyboard shortcut ALT SHIFT z (hotkey) with Selenium2?

风流意气都作罢 提交于 2019-11-26 22:59:57

问题


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")


来源:https://stackoverflow.com/questions/11520341/how-to-send-keyboard-shortcut-alt-shift-z-hotkey-with-selenium2

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!