2016-11-08 185 views
0

我無法執行鼠標懸停操作。我鏈接所有這些我不得不執行的操作,但我不能達到正確的元素鼠標懸停問題

我的代碼

Actions action = new Actions(driver); 
 

 
//1st Way 
 
action.moveToElement(driver.findElement(By.xpath("//div[@arid='app1575']//a"))).moveToElement(driver.findElement(By.xpath("//div[@arid='app1589']//a"))).click().build().perform(); 
 

 
//2nd Way 
 
    action.moveToElement(driver.findElement(By.xpath("//div[@arid='app1575']//a"))).perform(); 
 
    By locator = By.xpath("//div[@arid='app1589']//a"); 
 
    driver.findElement(locator).click();

我的HTML

<div class="flyout" style="height:100%;left:0;overflow:visible;width:100%;"> 
 
<div class="root root_menu" style="width: 100%; height: 25px; overflow: visible; background-color: rgb(33, 136, 201); border-top: 1px solid rgb(25, 102, 151); border-bottom: 1px solid rgb(255, 255, 255);" lvl="0" arid="app1575" artype="NavBarItem" navmode="1" arwindowid="0"> 
 
<a class="btn" onclick="javascript:" style="width:213px;z-index: 1;"> 
 
<span class="navLabel root " style="width: 100%;color:#ffffff;">Quick Links</span> 
 
</a> 
 
<div class="flyout" style="overflow: visible; left: 0px; border-right: 1px solid rgb(25, 102, 151); display: none; visibility: hidden; position: absolute; top: -1px; margin-left: 100%; margin-right: 0px;"> 
 
<div class="item EP lvl1 " style="height: 25px; overflow: visible; background-color: rgb(106, 184, 233); border-left: 1px solid rgb(106, 184, 233); border-top: medium none; border-bottom: medium none;" lvl="1" arid="app1576" artype="NavBarItem" navmode="1" arwindowid="0"> 
 
<a class="btn" onclick="javascript:CallARGSHR_58LHP_58CHP_58AppListEntryPointperfarsvrgrp_46nat_46bt_46comEPFunc(false, this);" style="z-index: 1;"> 
 
<span class="navLabel lvl1 " style="color: rgb(255, 255, 255);">Home Page</span> 
 
</a> 
 
</div> 
 
<div class="item EP lvl1 " style="height: 25px; overflow: visible; background-color: rgb(106, 184, 233); border-top: medium none; border-bottom: medium none;" lvl="1" arid="app1577" artype="NavBarItem" navmode="1" arwindowid="0"> 
 
<a class="btn" onclick="javascript:OpenAppWindow("/arsys/forms/perfarsvrgrp.nat.bt.com/AP%3AAdministration/Default+Administrator+View/?cacheid=d6be578&mode=CREATE",event);" style="z-index: 1;"> 
 
<span class="navLabel lvl1 " style="color: rgb(255, 255, 255);">Approval Administration Console</span> 
 
</a> 
 
</div> 
 
<div class="item EP lvl1 " style="height: 25px; overflow: visible; background-color: rgb(106, 184, 233); border-top: medium none; border-bottom: medium none;" lvl="1" arid="app1578" artype="NavBarItem" navmode="1" arwindowid="0"> 
 
<a class="btn" onclick="javascript:OpenAppWindow("/arsys/forms/perfarsvrgrp.nat.bt.com/NGSD%3AITSM+Configuration/New+View/?cacheid=44bb87f8&mode=CREATE",event);" style="z-index: 1;"> 
 
<span class="navLabel lvl1 " style="color: rgb(255, 255, 255);">Customer Configuration</span> 
 
</a> 
 
</div> 
 
<div class="item EP lvl1 " style="height: 25px; overflow: visible; background-color: rgb(106, 184, 233); border-top: medium none; border-bottom: medium none;" lvl="1" arid="app1579" artype="NavBarItem" navmode="1" arwindowid="0"> 
 
<a class="btn" onclick="javascript:OpenAppWindow("/arsys/forms/perfarsvrgrp.nat.bt.com/RJ%3ASQ2%3AProductCatalog/Default+Administrator+View__c/?cacheid=11b150e9",event);" style="z-index: 1;"> 
 
<span class="navLabel lvl1 " style="color: rgb(255, 255, 255);">RJ:SQ2:ProductCatalog</span> 
 
</a> 
 
</div>​

enter image description here

+0

什麼是你所得到的例外呢?只是徘徊在「快速鏈接」結果下一級菜單?或者我們是否需要明確點擊「快速鏈接」上的「右箭頭」鏈接? –

+0

沒有例外或錯誤。是的,只需將鼠標懸停在下一級菜單中的快速鏈接上。 –

+0

你能用代碼打開第二個菜單嗎?如果第二個菜單打開,那麼嘗試明確等待第二個菜單選項的可點擊性,即以第二種方式在點擊之前放置等待代碼。 – Grasshopper

回答

0

我嘗試了所有的可能性,最後如下代碼爲我工作使用。任何人都可以解釋爲什麼嗎?

Actions act=new Actions(driver); 
 
     act.moveToElement(driver.findElement(By.xpath("//div[@arid='app1575']//a"))).build().perform(); 
 
         
 
     Thread.sleep(1000); 
 
     
 
     JavascriptExecutor je = (JavascriptExecutor) driver; 
 
     je.executeScript("arguments[0].click();",driver.findElement(By.xpath("//div[@arid='app1589']//a")));

感謝所有爲您的支持

0

你可以試試下面的代碼,讓我知道它是如何工作的。

//To hover on TMD link 
Actions action = new Actions(driver); 
action.moveToElement(driver.findElement(By.xpath("//div[@arid='app1575']//a"))).click().build().perform(); 
Thread.sleep(2000); 
action.moveToElement(driver.findElement(By.xpath("//div[@arid='app1589']//a"))).build().perform(); 



//To click on TMD link 
Actions action = new Actions(driver); 
action.moveToElement(driver.findElement(By.xpath("//div[@arid='app1575']//a"))).click().build().perform(); 
Thread.sleep(2000); 
driver.findElement(By.xpath("//div[@arid='app1589']//a")).click(); 
0

試試下面的代碼:

WebElement ele=driver.findElement(By.xpath("xpath of quick links")); 
Actions act=new Actions(driver); 
act.moveToElement(ele).build().perform(); 
Thread.sleep(3000); 
driver.findElement(By.linkText("TMD")).click(); 
Thread.sleep(3000); 

檢查幀之前走這