如何在Java中将OpenLayers DrawFeature与Selenium WebDriver一起使用(双击问题)? [英] How to use OpenLayers DrawFeature with Selenium WebDriver in Java (double click issue)?

查看:131
本文介绍了如何在Java中将OpenLayers DrawFeature与Selenium WebDriver一起使用(双击问题)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在测试基于OpenLayers的GIS API.我使用Selenium WebDriver进行测试.我现在正在尝试测试OpenLayers.DrawFeature.当绘制点时,只需单击一下,它就可以很好地工作.但是对于直线和多边形则不是.

I am testing a GIS API that is based on OpenLayers. I use Selenium WebDriver to perform the tests. I am now trying to test the OpenLayers.DrawFeature. It works fine when drawing points, which require a single click. But for lines and polygons it doesn't.

线和面绘制需要双击以完成形状绘制.但是,Selenium WebDriver的"doubleClick()"方法似乎不起作用.

Line and polygon drawing requires a double click to finish drawing the shape. But, the "doubleClick()" method from Selenium WebDriver doe not seem to work.

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

It is a work task, so I can't paste the whole code, but here is what I think is the crucial part:

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();

正如您在此处看到的那样,尚未绘制多边形,因为双击不起作用:

As you can see here, the polygon is not drawn yet, because the double click didn't work:

如果双击成功,它应该是这样:

This is what it should look like, if the double click worked:

推荐答案

我可能已经找到了解决方案.可以,但是我不明白为什么.

I may have found a solution. It works, but I don't understand why.

代替:

act.doubleClick().perform();

我做到了:

act.click().doubleClick().build().perform();

因此,我执行一次普通单击,然后双击,然后创建动作并执行.

So, I perform a normal click, THEN a double click, I build the action, and perform.

正在工作.我能够完成绘图.

It is working. I am able to finish the drawing.

这篇关于如何在Java中将OpenLayers DrawFeature与Selenium WebDriver一起使用(双击问题)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆