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

  • 相关阅读:
    notification(浏览器通知)
    面试的信心来源于过硬的基础
    碰撞检测
    使用自定义的鼠标图标 --- cursor url
    js中json字符串转成js对象
    【php学习】字符串操作
    Car的旅行路线(codevs 1041)
    Find them, Catch them(poj 1703)
    Period(poj 1961)
    Power Strings(poj 2406)
  • 原文地址:https://www.cnblogs.com/fatfatdachao/p/4021911.html
Copyright © 2011-2022 走看看