selenium webdriver模拟键盘鼠标事件

上一篇 / 下一篇  2015-08-07 14:32:07 / 个人分类:selenium

我们在使用selenium webdriver进行自动化测试时,经常会用到模拟键盘鼠标的事件。我们可以用webdriver中的Actions.
1 移动鼠标

Actions action = new Actions(all.driver);

WebElement element1=all.driver.findElement(By.linkText("系统管理"));

action.moveToElement(element1).build().perform();

2 键盘按键模拟

WebElement ele = all.driver.findElement(By.xpath("//input[@ng-model='orgTree_searchStr']"));

ele.clear();

ele.sendKeys("长沙市");

Actions action = new Actions(all.driver);

action.sendKeys(ele,Keys.ENTER);

3 拖拽

Actions actions = new Actions(all.driver);

actions.clickAndHold(zhuzhou).moveToElement(hengyang,10,1).release().build().perform();

4 键盘鼠标组合

WebElement del1 = all.driver.findElement(By.xpath("//ul[@id='orgTree']/li/ul/li/a[@title='长沙市']"));

WebElement del2 = all.driver.findElement(By.xpath("//ul[@id='orgTree']/li/ul/li/a[@title='株洲市']"));

Actions actions = new Actions(all.driver);

actions.click(del1).keyDown(Keys.CONTROL).click(del2).keyUp(Keys.CONTROL).build().perform();


TAG: 键盘鼠标模拟

 

评分:0

我来说两句

我的栏目

日历

« 2024-03-26  
     12
3456789
10111213141516
17181920212223
24252627282930
31      

我的存档

数据统计

  • 访问量: 4078
  • 日志数: 3
  • 建立时间: 2015-08-07
  • 更新时间: 2015-08-25

RSS订阅

Open Toolbar