WebDriver之Modifier key



Java代码  收藏代码
  1. new Actions(driver).keyDown(Keys.CONTROL).keyDown(Keys.F5).keyUp(Keys.CONTROL).keyUp(Keys.F5).perform();  



Java代码  收藏代码
  1. java.lang.IllegalArgumentException: Key Down / Up events only make sense for modifier keys.  

Google 了一下Modifier Key:

  • Each key that appears on the keyboard without requiring modifiers are sent as a keydown followed by a key up.
  • If the server does not support native events and must simulate key strokes with JavaScript, it must generate keydown, keypress, and keyup events, in that order. The keypress event should only be fired when the corresponding key is for a printable character.
  • If a key requires a modifier key (e.g. "!" on a standard US keyboard), the sequence is: modifier down, keydown, key up, modifier up, where key is the ideal unmodified key value (using the previous example, a "1").
  • Modifier keys (Ctrl, Shift, Alt, and Command/Meta) are assumed to be "sticky"; each modifier should be held down (e.g. only a keydown event) until either the modifier is encountered again in the sequence, or the NULL (U+E000) key is encountered.
  • Each key sequence is terminated with an implicit NULL key. Subsequently, all depressed modifier keys must be released (with corresponding keyup events) at the end of the sequence.


所以CTRL属于Modifier Key,需要这样写:

Java代码  收藏代码
  1. Actions actionObject = new Actions(driver);        
  2.         actionObject.keyDown(Keys.CONTROL).sendKeys(Keys.F5).keyUp(Keys.CONTROL).perform();  


发布了430 篇原创文章 · 获赞 415 · 访问量 925万+


©️2019 CSDN 皮肤主题: 编程工作室 设计师: CSDN官方博客