zoukankan      html  css  js  c++  java
  • webDriver实现鼠标悬停

    需要导入action类,并且action类仅支持xpath的元素定位,对于cssSelector不支持。这个是本人调试过的经验之谈。

    在自动化测试过程中,由于javascript的使用,我们常常需要点击一些鼠标经过显示的菜单等元素,这时需要触发该元素的鼠标经过事件。使用WebDriver有以下两种实现。 
    1.使用Action 

    Java代码  收藏代码
    1. public void moveToElement(WebDriver driver, By locator) {  
    2.     Actions builder = new Actions(driver);  
    3.     builder.moveToElement(driver.findElement(locator)).perform();  
    4.  
    5. }  


    2.使用Sendkey 

    Java代码  收藏代码
    1. public void moveToElement(WebDriver driver, By locator) {  
    2.         driver.findElement(locator).sendKeys(Keys.DOWN);  
    3. }  


    说明:具体使用什么key,可以根据实际情况变化。例如左侧菜单可能是使用右箭头可以呼出子菜单。则应该使用Keys.RIGHT 

    Webdriver操作是很迅速的,假如一次moveTo你无法看到或者是无法进行操作,可以加上循环便可以达到效果。
    @Test
    public void BaiduTest() throws Exception {
    BaiduLogin();  
    BaiduLogout();
        }
     public void BaiduLogout()

    转自:http://www.366help.com/index.php?m=content&c=index&a=show&catid=14&id=686

  • 相关阅读:
    Sencha Touch 使用笔记
    区数据
    省市 数据
    js校验身份证
    js 邮政编码验证
    原生js添加class
    让IE6 IE7 IE8 IE9 IE10 IE11支持Bootstrap的解决方法
    js学习笔记 Function类型属性的理解
    js学习笔记 理解原型对象
    js学习笔记 chapter5 引用类型
  • 原文地址:https://www.cnblogs.com/fatfatdachao/p/4021911.html
Copyright © 2011-2022 走看看