java - 在 Java 中使用 Selenium 3 定位城市的纬度和经度
问题描述
我正在自动化 Webmap 操作,为此我必须将纬度-经度传递给 Chrome 浏览器,以便单击特定区域。
我了解 Selenium 4 具有使用 Chrome DevTools 执行此操作的功能。但由于项目限制,我只能使用 Selenium 3.12 或 3.14 实现这种自动化。
这是我尝试过的以下代码:
@Test
public void testLocationClick() {
int zoomActionCounter = 1;
while (findElement(By.className("leaflet-control-zoom-in")).isEnabled()) {
if (zoomActionCounter == 12) {
break;
}
findElement(By.className("leaflet-control-zoom-in")).click();
zoomActionCounter++;
}
((LocationContext)getDriver()).setLocation(new Location(37.774929, -122.419416, 0));
getDriver().get(SITE_URL);
WebElement map = getDriver().findElement(By.className("leaflet-interactive"));
waitForFewSeconds(1000);
map.click();
map.getLocation().getX();
map.getLocation().getY();
JavascriptExecutor js = (JavascriptExecutor) getDriver();
js.executeScript("window.navigator.geolocation.getCurrentPosition=function(success){"+
"var position = {\"coords\" : {\"latitude\": \"555\",\"longitude\": \"999\"}};"+
"success(position);}");
}
在这段代码中,我无法实现结果。任何线索都会有所帮助。
我必须将纬度和经度坐标传递给测试方法,以便点击事件发生在该坐标位置。
解决方案
推荐阅读
- reactjs - 在添加一些之前使用 UseState 重置值
- python - 在使用 pyenv 和诗歌创建的 python 3.9.2 虚拟环境中没有名为 _sqlite3 的模块
- sql - redshift 不允许我们将 varchar 字段更改为日期字段吗?
- c - 代码块调试模式监视选项灰显
- wordpress - 谷歌中带有 www 的搜索网站未在 wordpress 中显示预期结果
- javascript - Javascript 的实时服务器图像加载问题
- python - 'DataFrame' 对象没有属性 'col' 错误
- kaltura - 为什么 kaltura 热点链接不显示?
- pandas - 如何根据条件迭代熊猫数据框和块测试数据
- python - 获取“DataFrame”对象是可变的,因此在创建嵌套数组数据帧时它们不能被散列错误