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