Selenium学习8--截图,拖拽页面元素,键盘操作,鼠标右键,悬停,鼠标双击
2016-09-14 18:27
627 查看
1. 当前窗口截图
@Test public void captureScreenInCurrentWindow(){ driver.get("http:www.sogou.com"); File scrFile = ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE); try{ FileUtils.copyFile(scrFile, new File("D:\\screenshot.png")); }catch(Exception e){} }
2. 拖拽页面元素
@Ignore public void dragPageElement(){ driver.get("http://jqueryui.com/resources/demos/draggable/scroll.html"); WebElement draggable = driver.findElement(By.id("draggable")); //向下移动10个像素 for(int i = 0; i<5; i++){ new Actions(driver).dragAndDropBy(draggable, 0, 10).build().perform(); } //向右移动10个像素 for(int i=0; i<5;i++){ new Actions(driver).dragAndDropBy(draggable, 10, 0).build().perform(); } }
3. 模拟键盘点击
@Test public void keyDown(){ driver.get("http://www.sogou.com"); Actions action = new Actions(driver); //按下按钮 action.keyDown(Keys.CONTROL); action.keyDown(Keys.SHIFT); //释放按钮 action.keyUp(Keys.CONTROL); action.keyUp(Keys.SHIFT); //模拟键盘输入 action.keyDown(Keys.SHIFT).sendKeys("abdcsdf").perform(); }
4.鼠标右键
Actions action = new Actions(driver); //调用Action对象的contextClick方法 action.contextClick(driver.findElement(By.id("query"))).perform();
5. 鼠标悬停
action.moveToElement(link).perform();
6. 鼠标单击左键hold住, 然后释放
action.clickAndHold(div).perform(); action.release(div).perform();
7. 鼠标双击
@Test public void doubleClick(){ Actions action = new Actions(driver); action.doubleClick(findElement(By.id("inputBox")).build().perform(); }
相关文章推荐
- 20171012学习笔记Selenium 2 第四章WebDriver API 4.2控制浏览器 4.3简单元素操作4.4鼠标事件4.5键盘事件
- Selenium之元素进阶操作--鼠标左击,右击,双击,悬停(Action)的应用
- selenium webdriver学习(十三)------------如何利用Actions类模拟鼠标和键盘的操作
- 【selenium学习笔记】webdriver对页面元素的操作
- selenium webdriver学习(十三)------------如何利用Actions类模拟鼠标和键盘的操作
- selenium webdriver学习(十三)------------如何利用Actions类模拟鼠标和键盘的操作
- Python Selenium 学习笔记(三)键盘和鼠标操作
- Python Selenium 学习笔记(三)键盘和鼠标操作
- 【Selenium学习笔记】webdriver对鼠标的操作
- learning jQuery 学习笔记十二(+jQuery 1.4.1 API)-- DOM操作-基于命令改变页面 ----包装元素
- selenium 总结篇,常见方法和页面元素的操作
- 自学selenium练习题第四节-页面元素基本操作
- jquery鼠标 左键-中键-右键 实现 单击-双击-拖拽-滚动 原型
- Extjs学习总结之06页面元素操作和模版
- qtp录制鼠标右键单击事件要通过模拟键盘操作来实现
- selenium webdriver学习(四)------------定位页面元素(转)
- Selenium操作页面元素
- Selenium(五)――webdriver 之操作页面元素
- [Selenium] 操作页面元素等待时间
- selenium webdriver学习(十一)-怎么等待页面元素加载完成