我正在测试基于OpenLayers的GIS API。我使用Selenium WebDriver来执行测试。我现在正在尝试测试OpenLayers.DrawFeature。它在绘制点时工作正常,只需单击一下即可。但对于线条和多边形,它并不是。
线条和多边形绘图需要双击才能完成绘制形状。但是," doubleClick()"来自Selenium WebDriver doe的方法似乎不起作用。
这是一项工作任务,所以我无法粘贴整个代码,但我认为这是关键部分:
driver = new ChromeDriver();
Global.initWithCookies(driver);
WebElement el = driver.findElement(By.id(Menu.idOfDrawModesBtn()));
Actions act = new Actions(driver);
act.moveToElement(el).perform();
driver.findElement(By.id(Menu.idOfDrawModePolygonBtn())).click();
el = driver.findElement(By.id(Global.idOfMapDiv()));
act.moveToElement(el).perform();
// First click at the center of the map
act.click().perform();
// Moves to 2nd location
act.moveByOffset(100, 10).perform();
// 2nd click creates the 2nd vertex of the polygon
act.click().perform();
// Moves to 2nd location
act.moveByOffset(200, -200).perform();
/* Double click creates the 3rd vertex of the polygon
AND should finish the drawing */
act.doubleClick().perform();
driver.close();
正如您在此处所看到的,多边形尚未绘制,因为双击不起作用:
如果双击工作,它应该是这样的:
答案 0 :(得分:0)
我可能找到了解决方案。它有效,但我不明白为什么。
而不是:
act.doubleClick().perform();
我做了:
act.click().doubleClick().build().perform();
所以,我执行正常点击,然后双击,我构建动作,然后执行。
它正在发挥作用。我能够完成绘图。