【问题标题】:How to drag and drop the angular element using co-ordinates in Robot Framework如何在机器人框架中使用坐标拖放角度元素
【发布时间】:2021-02-28 08:59:24
【问题描述】:

我正在尝试使用 Robot Framework 自动化这个 Angular 应用程序。 我正在尝试使用 drag and drop by offset 关键字来拖放矩形。 手动场景是当我单击矩形的中间并拖动时,它会拖动箭头。代码更改为 <g transform="translate(0.5,0.5)" style="visibility: visible; cursor: pointer;"> 。 如果我拖动边缘,矩形将是可移动的,代码更改为<g transform=" translate(0.5,0.5)" style=" visibility: visible; cursor: move; 我想通过单击边来拖放矩形。我尝试的所有 xpath 都在中间单击并拖动箭头。

如果有人知道如何使用 SVG 编写 xpath,请帮帮我。

        <svg style="width: 100%; height: 100%; display: block; min-width: 1081px; min-height: 384px;">
       <g>
          <g></g>
          <g>
             <g transform="translate(0.5,0.5)" style="visibility: visible;">
                <ellipse cx="132" cy="132" rx="32" ry="32" fill="black" stroke="black" transform="translate(0,3)" opacity="0.2"></ellipse>
                <ellipse cx="132" cy="132" rx="32" ry="32" fill="#f5f5f5" stroke="#f5f5f5" pointer-events="all"></ellipse>
             </g>
             <g style="">
                <g fill="#000000" font-family="Roboto" font-weight="bold" text-anchor="middle" font-size="14px">
                   <text x="132" y="137">New</text>
                </g>
             </g>
             <g transform="translate(0.5,0.5)" style="visibility: visible; cursor: move;">
                <rect x="960" y="300" width="120" height="80" fill="black" stroke="black" transform="translate(0,3)" opacity="0.2"></rect>
                <rect x="960" y="300" width="120" height="80" fill="#2196f3" stroke="#2196f3" pointer-events="all"></rect>
             </g>
             <g style="cursor: move;">
                <g fill="#000000" font-family="Roboto" font-weight="bold" text-anchor="middle" font-size="14px">
                   <text x="1020" y="345">test</text>
                </g>
             </g>
          </g>
          <g></g>
          <g></g>
       </g>
    </svg>

我尝试了很多 xpath。但他们都没有帮助我拖动矩形。我尝试的所有 xpath 都在矩形之间单击并导致箭头。 一些 xpath 尝试过:

  1. (//[name()='svg']///)[3]
  2. (//[local-name()='svg']//[name()='g'])[7]//*[local-name()='矩形'][1]
  3. (//[local-name()='svg']//[name()='g'])[7]//*[local-name()='矩形'][2]

提前致谢。

【问题讨论】:

    标签: selenium selenium-webdriver xpath robotframework


    【解决方案1】:

    默认的 Selenium 行为是点击元素的中心。 为此,我将使用 java.awt.Robot

    在 Java 中,它会类似于

    Robot r = new Robot();
    Point p = findElement(locator).getLocation();
    r.mouseMove(p.x + someXOffsetFromTheCenter, p.y + someYOffsetFromTheCenter);
    //then use Actions to drag and drop to the destination (you should determine the destination the same way as the origin - [x,y])
    Actions action = new Actions(driver);
    action.click().moveByOffset(x,y).release().build().perform();
    //alternatively, if you can drop to the center of the destination element, you could do
    action.click().moveToElement(destinationElem).release().build().perform();
    

    【讨论】:

      猜你喜欢
      • 2021-05-14
      • 1970-01-01
      • 1970-01-01
      • 2021-03-19
      • 1970-01-01
      • 1970-01-01
      • 2019-12-03
      • 1970-01-01
      • 2020-05-23
      相关资源
      最近更新 更多