2013-03-06 21 views
0

我正在使用Selenium WebDriver沃爾瑪自動化。我已經寫了一個功能,將鼠標懸停在部門菜單「家庭,傢俱&庭院」上,以便突出顯示,並且我可以點擊「設備」鏈接。這是我寫的功能,但它似乎沒有懸停在元素上。我如何執行鼠標單擊鼠標懸停的動態菜單項在硒2.0

public void NavigateDepartments(){ 
     WebElement ApplianceLink = driver.findElement(By.xpath("//*[div='Home, Furniture & Patio']")); 
    Actions myMouse = new Actions(driver); 
     myMouse.moveToElement(ApplianceLink).build().perform(); 
    ApplianceLink.click(); 

} 

我還試圖給出絕對路徑 的Xpath( 「/ HTML /體/ DIV/DIV/DIV [3]/DIV/DIV/DIV/UL /鋰[3]/DIV/DIV」)找到元素,它也不起作用。我錯過了什麼?

+0

什麼驅動程序版本和瀏覽器版本? – 2013-03-06 09:31:42

回答

2

在主菜單中你應該先懸停,然後移動到新的元素

WebElement menu = driver.findElement(By.xpath("//path to *appliance*")); 
WebElement parentMenu = driver.findElement(By.xpath("//*[div='Home, Furniture & Patio']")); 
Actions builder = new Actions(driver); 
builder.moveToElement(parentMenu).moveToElement(menu).click().build().perform();