• 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

  • 相关阅读:
    Python 对象的绑定方法
    Python 类的属性
    Python 对象与类
    Python 面向对象
    Python Subprocess模块
    Python Hashlib模块
    Python Configparser模块
    Python XML模块
    Python Re模块
    Gridview中Datakeys 通过主键取得各列的值。(转)
  • 原文地址:https://www.cnblogs.com/fatfatdachao/p/4021911.html
Copyright © 2020-2023  润新知