2015-02-06 48 views
0

我有一個菜單有 (列表)元素,鼠標懸停特定標籤後啓用。硒 - 無法點擊動態可見菜單

driver.get("www.snapdeal.com"); Actions actions = new Actions(driver); 
    actions.moveToElement(driver.findElement(By.id("loggedOutAccount"))).build().perform(); 
    //Wait for 5 Secs 
    driver.findElement(By.className("accountLink")).click();// Here it's throwing Element not visible exception 

此代碼正在進行鼠標懸停,但無法點擊「SignIn Link」鏈接。雖然手動檢查元素可見

DOM結構 -

<div id="loggedOutAccount" class="hd-rvmp-logout"> 
<a class="signIn" href="javascript:void(0);"> 
<i class="iconHeader accountUser"></i> 
<label class="my-account-lang"> My Account</label> 
<i class="mar_2_left right-downArrow breadcrumbArrow-down"></i> 
</a> 
<div class="sdNavDropWrapper accDetails" style="display: none; z-index: 999;"> 
<ul class="positionAbsolute pull-right"> 
<li class="customLoggedInState"> 
<div class="left triangle"></div> 
<div class="right triangle"></div> 
<div> 
<a class="accountLink" href="javascript:void(0);">Click here to sign in ></a> 
</div> 
</li> 
<li class="stop-event"> 
<li class="stop-event"> 
<li class="stop-event"> 
<li class="stop-event"> 
<li class="stop-event"> 
</ul> 
</div> 
</div> 
+0

當您刪除鼠標懸停時,該元素是否會再次隱藏? – 2015-02-06 10:19:35

+0

是的......一旦鼠標懸停被刪除,元素會再次隱藏。 – br001 2015-02-06 10:23:11

+0

您可以使用xpath來查找這兩個元素嗎?註銷按鈕和帳戶鏈接? – 2015-02-06 10:27:22

回答

1

請使用XPath兩個元素象下面這樣:

driver.get("www.snapdeal.com"); 
Actions actions = new Actions(driver); 
actions.moveToElement(driver.findElement(By.xpath("yourxpathhere"))).build().perform(); 

driver.findElement(By.xpath("yourxpathhere")).click(); 

我認爲類/身份證重複其他元素也爲樣式目的。所以Xpath最好找到獨特的元素。