如何在Java中使用OpenLayers DrawFeature和Selenium WebDriver(双击问题)?

如何在Java中使用OpenLayers DrawFeature和Selenium WebDriver(双击问题)?,java,selenium-webdriver,openlayers,double-click,Java,Selenium Webdriver,Openlayers,Double Click,我正在测试一个基于OpenLayers的GIS API。我使用SeleniumWebDriver来执行测试。我现在正在尝试测试OpenLayers.DrawFeature。当绘制需要单击的点时,它可以正常工作。但对于直线和多边形,情况并非如此 绘制直线和多边形需要双击以完成绘制形状。但是,SeleniumWebDriver中的“doubleClick()”方法似乎不起作用 这是一项工作任务,因此我无法粘贴整个代码,但我认为这是关键部分: driver = new ChromeDriver();

我正在测试一个基于OpenLayers的GIS API。我使用SeleniumWebDriver来执行测试。我现在正在尝试测试OpenLayers.DrawFeature。当绘制需要单击的点时,它可以正常工作。但对于直线和多边形,情况并非如此

绘制直线和多边形需要双击以完成绘制形状。但是,SeleniumWebDriver中的“doubleClick()”方法似乎不起作用

这是一项工作任务,因此我无法粘贴整个代码,但我认为这是关键部分:

driver = new ChromeDriver();
Global.initWithCookies(driver);

// Gets the button to select a shape to draw
WebElement el = driver.findElement(By.id(Menu.idOfDrawModesBtn()));
// Creates an action
Actions act = new Actions(driver);
// Moves the cursor to the element
act.moveToElement(el).perform();
// Gets the button to draw a polygon
driver.findElement(By.id(Menu.idOfDrawModePolygonBtn())).click();
// Gets the map element
el = driver.findElement(By.id(Global.idOfMapDiv()));
// Moves the cursor to the element
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();
如您所见,多边形尚未绘制,因为双击不起作用:

如果双击起作用,它应该是这样的:


我可能已经找到了解决办法。这很有效,但我不明白为什么

而不是:

act.doubleClick().perform();
我做到了:

act.click().doubleClick().build().perform();
所以,我执行一个普通的点击,然后双击,我构建动作,然后执行


它正在工作。我能够完成绘图。

嗨,joaorodr84,我有一个类似的问题,但不适合绘图。。。我必须在基于OpenLayers 2.x(ExtJS)的地图上确定一个功能。你有样本吗?嗨@joaorodr84我在计算从中心到多边形的偏移值时有问题,你知道如何计算这些值吗?你好,joaorodr84谢谢你的回答。这对我也很有用,但你能解释一下你的这三行代码吗?”driver.findElement(By.id(Menu.idOfDrawModePolygonBtn())。单击();“”el=driver.findElement(By.id(Global.idOfMapDiv());“”act.moveToElement(el.perform();'谢谢你advance@Me_developer我刚刚在主要帖子中添加了评论。希望他们能帮忙@joaorodr84非常感谢。:)