如何使用量角器单击传单地图的中心
How to click on the center of a leaflet map using protractor
我试图点击页面第二列地图的中心(因此它有一个偏移量)但是它不起作用,光标似乎总是指向中心页面的 :
我正在尝试用 width/height 的一半添加位置,这是代码:
it('should select center point', async () => {
const map = pageObject.getMap(); // $('.map-container')
const size = await map.getSize();
const location = await map.getLocation();
const halfWidth = parseInt(await map.getAttribute('clientWidth'), 10) / 2;
const halfHeight = parseInt(await map.getAttribute('clientHeight'), 10) / 2;
const x = location.x + halfWidth;
const y = location.y + halfHeight;
await browser
.actions()
.mouseMove(map, { x, y })
.click()
.perform();
console.log('size', size); { height: 482, width: 840 }
console.log('location', location); { x: 523, y:145 }
console.log('halfWidth', halfWidth); // 420
console.log('halfHeight', halfHeight); // 241
console.log('x', x); // 943
console.log('y', y); // 386
debugger;
});
window大小是1380*668
所以943
和386
似乎是正确的,我不知道为什么它不起作用。
我也尝试过不处理偏移量,但它不起作用:
await browser
.actions()
.mouseMove(map, { x: halfWidth, y: halfHeight })
.click()
.perform();
我尝试使用 map.getWebElement()
来更改选择器,但没有任何效果
所以我找到了一个解决方案,默认情况下,当我点击地图元素时,量角器点击中心:
await pageObject.getMap().click();
要单击特定地址,我直接在地理编码器栏上键入地址,然后单击地图以获取中心,但我没有找到 moveMove(element, { x, y })
的解决方案
我试图点击页面第二列地图的中心(因此它有一个偏移量)但是它不起作用,光标似乎总是指向中心页面的 :
我正在尝试用 width/height 的一半添加位置,这是代码:
it('should select center point', async () => {
const map = pageObject.getMap(); // $('.map-container')
const size = await map.getSize();
const location = await map.getLocation();
const halfWidth = parseInt(await map.getAttribute('clientWidth'), 10) / 2;
const halfHeight = parseInt(await map.getAttribute('clientHeight'), 10) / 2;
const x = location.x + halfWidth;
const y = location.y + halfHeight;
await browser
.actions()
.mouseMove(map, { x, y })
.click()
.perform();
console.log('size', size); { height: 482, width: 840 }
console.log('location', location); { x: 523, y:145 }
console.log('halfWidth', halfWidth); // 420
console.log('halfHeight', halfHeight); // 241
console.log('x', x); // 943
console.log('y', y); // 386
debugger;
});
window大小是1380*668
所以943
和386
似乎是正确的,我不知道为什么它不起作用。
我也尝试过不处理偏移量,但它不起作用:
await browser
.actions()
.mouseMove(map, { x: halfWidth, y: halfHeight })
.click()
.perform();
我尝试使用 map.getWebElement()
来更改选择器,但没有任何效果
所以我找到了一个解决方案,默认情况下,当我点击地图元素时,量角器点击中心:
await pageObject.getMap().click();
要单击特定地址,我直接在地理编码器栏上键入地址,然后单击地图以获取中心,但我没有找到 moveMove(element, { x, y })