在我们使用selenium 1.0的时候,如果需要选择多行,可以模拟键盘操作按下Ctrl以及放开Ctrl键来控制,提供的API为:
selenium.controlKeyDown();
//select action
selenium.controlKeyUp();
可是到了selenium 2上,我们会发现这些函数已经失效了。那么,我们就必须要借助于WebDriver提供的Action来实现等效功能。
http://selenium.googlecode.com/git/docs/api/java/org/openqa/selenium/interactions/Actions.html
Actions提供给了我们模拟复杂的用户操作的API,它能够用来替换对Keyboard及Mouse的直接使用。可以调用该类的多个动作方法来建立一个组合Action。
例1:模拟按键Ctrl+F5
Ctrl is a modifier key but F5 is not. You probably want to use:
Actions actionObject = new Actions(webDriver);
actionObject.keyDown(Keys.CONTROL).sendKeys(Keys.F5).keyUp(Key