您的位置:首页 > 其它

Selenium键盘鼠标操作总结

2016-04-10 21:27 246 查看
鼠标操作

org.openqa.selenium.interactions.Actions 





1、给元素设置焦点。

有时对于a标签等,为了不跳转到别的链接,但是需要设置焦点时就可使用。

action.moveToElement(e); //移动鼠标到元素。
action.perform();//点击右键。

键盘操作

java.awt.Robot



1、输入各键盘值

(1)元素直接输入值。

WebElement e=test.web.findElement(By.id("hfCityBox"));

e.sendKeys("你好");

(2)Actions输入值。

Actions action = new Actions(test.web);

action.sendKeys(e, "ss");

注:Actions 的 sendKeys(keysToSend) 执行完之后,焦点就不在当前元素了。

(3)Robot触发按键事件。

Robot robot=null;
try {
robot = new Robot();
} catch (AWTException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}

robot.keyPress(KeyEvent.VK_0)//按下键盘0键。

robot.keyRelease(KeyEvent.VK_0);//放开键盘0键。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: