Selenium之当鼠标悬浮时隐藏的元素才出现


在自动化过程中,有些导航按钮只有当鼠标悬浮在登录信息上时,它才能出现。这时候如果想要点击导航按钮直接用selenium的webDriver是无法定位的元素的,因为这些元素是隐藏的,只有鼠标悬浮时才出现,所以要记录一下,给大家一个参考

            Actions action = new Actions(driver);     
            WebElement nav=driver.findElement(By.xpath("/html/body/div[1]/div/div[1]/div[2]/div/ul/li/a/span"));
            //if found the link, then hover over the link to display the menu.
            if(nav.isDisplayed()){
                System.out.println("found=================");
                action.moveToElement(nav).build().perform();
            }
            
    //        action.moveToElement(nav).moveByOffset(3, 3).build().perform();
            //click the displayed menu
    //        driver.findElement(By.xpath("/html/body/div[1]/div/div[1]/div[2]/div/ul/li/ul/li[2]/a")).click();  
            //click the logout menu via js
            JavascriptExecutor js = (JavascriptExecutor) driver;
            WebElement logout=driver.findElement(By.xpath("//a[contains(@href, '/GlobalDataTaxonomy/user/signout')]"));  
    //        String myjs="$('//a[contains(@href, '/GlobalDataTaxonomy/user/signout')]').click();";
            js.executeScript("arguments[0].click();",logout);    
            driver.close();


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM