我正在测试一个基于 OpenLayers 的 GIS API。我使用 Selenium WebDriver 来执行测试。我现在正在尝试测试 OpenLayers.DrawFeature。它在绘制点时效果很好,需要单击一下。但对于直线和多边形则不然。
直线和多边形绘制需要双击才能完成形状的绘制。但是,Selenium WebDriver 中的“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();
I did:
act.click().doubleClick().build().perform();
因此,我执行正常单击,然后双击,构建操作并执行。
这是工作。我能够完成这幅画。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)