在画布标签内选择元素

时间:2019-05-15 09:14:12

标签: selenium

enter image description here我必须单击地图,然后从那里选择一个位置。它在画布标签内。我该如何使用硒呢?

HTML代码-

<canvas class="leaflet-zoom-animated" width="3740" height="1408" style="transform: translate3d(-153px, -59px, 0px); width: 1870px; height: 704px;"></canvas>

硒无法单击。

1 个答案:

答案 0 :(得分:0)

  1. 要使用Actions链执行,下面是类似于Java的示例C#代码
    IWebElement canvas = driver.FindElement(By.Id("TimeZoneId"));
    int xCo = canvas.Location.X;
    int yCo = canvas.Location.Y;Actions action = new Actions(driver);
    action.MoveToElement(canvas, 'your x coordinates' + xCo, 'your y coordinates' + yCo).Click().Build().Perform();
  1. 尝试OpenCV
  2. 如果要在地图上测试叠加层。使用JavaScriptExecutor,并在代码中添加hooks,以便在地图中执行操作。