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

  • 相关阅读:
    pandas read_excel 产生 Unnamed:0 列
    python 打印输出百分比符号%
    python 内存回收
    python 编码问题
    python 判断 txt 编码方式
    python 二维list取列
    python 两个list 求交集,并集,差集
    pandas Timestamp的用法
    Dataframe 取列名
    Dataframe 新增一列, apply 通用方法
  • 原文地址:https://www.cnblogs.com/fatfatdachao/p/4021911.html
Copyright © 2011-2022 走看看