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

  • 相关阅读:
    反射的概述_反射应用实例
    日期类之SimpleDateFormat
    StringBuffer & StringBuilder
    String与包装类_字节数组_字符数组间的转换
    两种方法k8s安装dashboard组件
    git学习
    Prometheus搭建
    python学习博客
    Python的全局变量和局部变量
    python参数
  • 原文地址:https://www.cnblogs.com/fatfatdachao/p/4021911.html
Copyright © 2011-2022 走看看