您的位置:軟件測(cè)試 > 開(kāi)源軟件測(cè)試 > 開(kāi)源功能測(cè)試工具 > Selenium
Selenium之當(dāng)鼠標(biāo)懸浮時(shí)隱藏的元素才出現(xiàn)
作者:網(wǎng)絡(luò)轉(zhuǎn)載 發(fā)布時(shí)間:[ 2015/5/27 14:41:19 ] 推薦標(biāo)簽:功能測(cè)試工具

  在自動(dòng)化過(guò)程中,有些導(dǎo)航按鈕只有當(dāng)鼠標(biāo)懸浮在登錄信息上時(shí),它才能出現(xiàn)。這時(shí)候如果想要點(diǎn)擊導(dǎo)航按鈕直接用selenium的webDriver是無(wú)法定位的元素的,因?yàn)檫@些元素是隱藏的,只有鼠標(biāo)懸浮時(shí)才出現(xiàn),所以要記錄一下,給大家一個(gè)參考
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();

軟件測(cè)試工具 | 聯(lián)系我們 | 投訴建議 | 誠(chéng)聘英才 | 申請(qǐng)使用列表 | 網(wǎng)站地圖
滬ICP備07036474 2003-2017 版權(quán)所有 上海澤眾軟件科技有限公司 Shanghai ZeZhong Software Co.,Ltd