首页 > 解决方案 > 如何使用量角器单击传单地图的中心

问题描述

我正在尝试单击页面第二列上的地图中心(因此它有一个偏移量)但它不起作用,似乎光标总是指向页面的中心:

在此处输入图像描述

我正在尝试使用宽度/高度的一半来添加位置,这是代码:

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

窗口大小是1380*668如此943386似乎是正确的,我不知道为什么它不起作用。

我也尝试过不处理偏移量,但它不起作用:

    await browser
              .actions()
              .mouseMove(map, { x: halfWidth, y: halfHeight })
              .click()
              .perform();

我尝试使用map.getWebElement(), 来更改选择器,但没有任何效果

标签: angulartypescriptseleniumprotractorleaflet

解决方案


所以我找到了一个解决方案,默认情况下,当我点击地图元素时,量角器点击中心:

await pageObject.getMap().click();

要单击特定地址,我直接在地理编码器栏上输入地址,然后单击地图以获取中心,但我没有找到解决方案  moveMove(element, { x, y })


推荐阅读