鼠标悬停问题

时间:2016-11-08 06:41:23

标签: selenium-webdriver

我无法执行鼠标悬停操作。我正在链接我必须执行的所有操作,但我无法达到正确的元素

我的代码



<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>​
&#13;
&#13;
&#13;

我的HTML

&#13;
&#13;
"this" is undefined
&#13;
&#13;
&#13;

enter image description here

3 个答案:

答案 0 :(得分: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();

答案 1 :(得分: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);

在使用此

之前检查帧

答案 2 :(得分:0)

我尝试了所有的概率,最后下面给出的代码对我有用。任何人都可以解释我为什么这样吗?

&#13;
&#13;
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")));
&#13;
&#13;
&#13;

感谢所有人的支持