Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/logging/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Selenium webdriver 如何在selenium中使用mouseMove单击子菜单_Selenium Webdriver - Fatal编程技术网

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

Selenium webdriver 如何在selenium中使用mouseMove单击子菜单,selenium-webdriver,Selenium Webdriver,我想在我下面的代码中单击子菜单Coordinates 2。我使用WebElement尝试过这种方法。但它不起作用。菜单将处于鼠标悬停功能。请帮助我解决这个问题 Point coordinates = driver.findElement(By.xpath("html/body/div[3]/div[1]")).getLocation(); Point coordinates1 = driver.findElement(By.xpath("html/body/div[4]/div[

我想在我下面的代码中单击子菜单Coordinates 2。我使用WebElement尝试过这种方法。但它不起作用。菜单将处于鼠标悬停功能。请帮助我解决这个问题

    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>

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

您能提供html代码吗?我在这里展示了一个示例,对于Etsy.com搜索页面:我甚至尝试过使用Webelement。但没有改变。有什么建议吗?使用Firefox Firebug的FirePath插件可以帮助您发现菜单的定位器,还可以测试css和xpath选择器,而无需编写代码。