zoukankan      html  css  js  c++  java
  • 【转载】WebDriver常用的鼠标/键盘操作

    注:driver为一个WebDriver的实例,xpath为一个元素的xpath字符串,在本文中一律采用xpath的方式定位元素

    1、鼠标右键点击操作:
    Actions action = new Actions(driver) ;
    action.contextClick(driver.findElement(By.xpath(xpath))) ;


    2、鼠标左键双击操作:
    Actions action = new Actions(driver) ;
    action.doubleClick(driver.findElement(By.xpath(xpath))) ;


    3、鼠标左键按下操作:
    Actions action = new Actions(driver) ;
    action.clickAndHold(driver.findElement(By.xpath(xpath))) ;


    4、鼠标左键抬起操作:
    Actions action = new Actions(driver) ;
    action.release(driver.findElement(By.xpath(xpath))) ;


    5、鼠标移动到元素上操作:
    Actions action = new Actions(driver) ;
    action.moveToElement(driver.findElement(By.xpath(xpath))) ;


    6、组合的鼠标操作(将目标元素拖拽到指定的元素上):
    Actions action = new Actions(driver) ;
    action.dragAndDrop(driver.findElement(By.xpath(xpath)),driver.findElement(By.xpath(xpath))) ;


    7、组合的鼠标操作(将目标元素拖拽到指定的区域里):
    Actions action = new Actions(driver) ;
    action.dragAndDrop(driver.findElement(By.xpath(xpath)),xOffset,yOffset) ;


    8、键盘的按下操作:
    Actions action = new Actions(driver) ;
    action.keyDown(driver.findElement(getBy()),key) ;注:key 为一个Keys的实例,实例化一个F1的按键则为Keys.F1


    9、按钮松开操作:
    Actions action = new Actions(driver) ;
    action.keyUp(driver.findElement(getBy()),key) ;

  • 相关阅读:
    [转载]努力吧,现在也不晚
    注册码
    SpringMVC中JSP取不到ModelAndView,ModelMap的数据原因
    《Maven实战》阅读笔记
    Nosql之Redis篇
    strong和b
    html中的元素和节点
    CSS2伪类选择器要点
    Sublime Text 2 安装 zen coding (Emmet)
    java-Cannot reduce the visibility of the inherited method from 父类
  • 原文地址:https://www.cnblogs.com/wxll/p/5980531.html
Copyright © 2011-2022 走看看