【问题标题】:How to click on the center of a leaflet map using protractor如何使用量角器单击传单地图的中心
【发布时间】:2020-03-09 06:49:46
【问题描述】:

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

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

    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() 来更改选择器,但没有任何效果

【问题讨论】:

    标签: angular typescript selenium protractor leaflet


    【解决方案1】:

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

    await pageObject.getMap().click();
    

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

    【讨论】:

      猜你喜欢
      • 2015-10-13
      • 2022-01-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-08-11
      • 1970-01-01
      相关资源
      最近更新 更多