如何在selenium中使用mouseMove单击子菜单

时间:2013-12-23 11:47:47

标签: selenium-webdriver

我想在下面的代码中单击子菜单(coordinates2)。我已经尝试使用WebElement这样的方法。但是它不起作用。菜单将鼠标悬停在funtion.Pls帮我解决这个问题。

    Point coordinates = driver.findElement(By.xpath("html/body/div[3]/div[1]")).getLocation();
    Point coordinates1 = driver.findElement(By.xpath("html/body/div[4]/div[1]")).getLocation();
    Point coordinates2 = driver.findElement(By.xpath("html/body/div[5]/div[1]")).getLocation();
    Robot robot = new Robot();
    robot.mouseMove(coordinates.getX()+3,coordinates.getY()+150);
    robot.mouseMove(coordinates1.getX()+50,coordinates1.getY()+240);
    driver.manage().timeouts().implicitlyWait(0, TimeUnit.SECONDS);
    robot.mouseMove(coordinates2.getX()+200,coordinates2.getY()+240);

以下是Html代码。

<body marginwidth="0" marginheight="0" bgcolor="" onload="dyninit();init();" topmargin="0" leftmargin="0">
<div id="transboxdiv" class="transbox">
<iframe id="disablePageframe" scrolling="no" style="z-index: 150;position:absolute;display:none;background-color:#ffffcc;border: 0 solid black; allowtranaparency:true"/>
<div id="disablePage" class="options" border="0" style="z-index:150; font-family:'Microsoft Sans Serif';font-size:13px;display:none;position:absolute;text-align:center;"/>

<div style="position: absolute; visibility: visible; background-color: rgb(255, 255, 255); width: 617px; height: 20px; font-family: Verdana,Arial,Helvetica,sans-serif; font-weight: normal; font-style: normal; font-size: 8pt; z-index: 101; top: 64px; left: 0px;">
<div style="position: absolute; visibility: inherit; overflow: hidden; cursor: default; color: rgb(255, 255, 255); background-color: rgb(25, 63, 148); text-align: left; width: 65px; height: 16px; padding-left: 0px; padding-top: 2px; left: 1px; top: 1px;">Masters</div>
</div>

<div style="position: absolute; visibility: visible; background-color: rgb(255, 255, 255); width: 142px; height: 236px; font-family: Verdana,Arial,Helvetica,sans-serif; font-weight: normal; font-style: normal; font-size: 8pt; z-index: 102; top: 84px; left: 0px;">
<div style="position: absolute; visibility: inherit; overflow: hidden; cursor: default; color: rgb(255, 255, 255); background-color: rgb(25, 63, 148); text-align: left; width: 140px; height: 16px; padding-left: 0px; padding-top: 2px; left: 1px; top: 1px;">Material Group</div>
</div>

<div style="position: absolute; visibility: visible; background-color: rgb(255, 255, 255); width: 162px; height: 56px; font-family: Verdana,Arial,Helvetica,sans-serif; font-weight: normal; font-style: normal; font-size: 8pt; z-index: 103; top: 85.8px; left: 127px;">
<div style="position: absolute; visibility: inherit; overflow: hidden; cursor: default; color: rgb(255, 255, 255); background-color: rgb(25, 63, 148); text-align: left; width: 160px; height: 16px; padding-left: 0px; padding-top: 2px; left: 1px; top: 1px;">Material Group-Add</div>
</div>

1 个答案:

答案 0 :(得分:0)

单击子菜单很容易。单击菜单并显示内容后,页面DOM可能会更改并加载菜单内容。此时,您应该能够看到页面源中的元素,并使用Selenium getElements(By)方法将它们作为列表进行迭代。