【问题标题】:Using protractor typescript, how do i detect this element square white box, then click and drag the white box, it has ng-mousedown and transform使用量角器打字稿,我如何检测这个元素方形白框,然后单击并拖动白框,它有 ng-mousedown 和变换
【发布时间】:2019-05-26 19:42:29
【问题描述】:

我需要帮助来为此创建打字稿/javascript 量角器代码吗?用于网络自动化。

如何单击此白框并将其从左向右拖动?

从左向右拖动,也会将transform="translate(205)" 的值更改为transform="translate(206)" 以及<text>2/20/18</text>

网站代码:

<g id="IndicateNav" ng-attr-trnsform="translate({{trVM._indicate || 0}})" ng-mousedown="trVM.mousedown($event, 'indicator')" ng-show="trVM._indicate" class="move-horizonal show-label-on-hover" transform="translate(205)">
   <line x1="0" x2="0" ng-attr-y1="{{trVM.bTop}}" ng-attr-y2="{{trVM.height}}" stroke="black" stroke-width="2" y1="20" y2="45"></line>
        <g ng-attr-trnsform="translate(0,{{trVM.bTop + ( (trVM.height - trVM.bTop) / 2) }})" transform="translate(0,32.5)">
            <square sx="0" sy="0" r="6" fill="white" stroke="black" stroke-width="2" ng-non-bindable=""></square>
        </g>
            <text x="14" ng-attr-y="{{3 + trVM.bTop + ( (trVM.height-trVM.bTop) / 2 )}}" text-anchor="start" font-size="12px" fill="white" style="pointer-events:none;" y="35.5">2/20/18</text>
</g>

【问题讨论】:

    标签: angular typescript jasmine protractor webautomation


    【解决方案1】:

    您可以利用browser.actions() 提供的功能。

    解决方案:

    1. 将 id 添加到 square 标签 [假设 id 是“whiteBox”]。
    2. 获取“whiteBox”元素并将其保存到变量中。

      const whiteBox = element(by.css('#whiteBox'));
      
    3. 通过以下代码模拟用户的拖动行为:

      browser.actions().mouseDown(whiteBox).mouseMove({x: 50, y: 0}).mouseUp().perform()  
      

      这会将 whiteBox 向右移动 50 像素。

    4. 如果您想将“whiteBox”拖到其他元素,您也可以这样做:

      browser.actions().mouseDown(whiteBox).mouseMove(element2).mouseUp().perform()  
      

    完整的测试代码:

    describe('whiteBox Dragging Test', function() {
      it('Drag whiteBox to right', function () {
        const EC = protractor.ExpectedConditions;
        const whiteBox = element(by.css('#whiteBox'));
        browser.wait(EC.presenceOf(whiteBox), 5000).then(() => {
          browser.actions().mouseDown(whiteBox).mouseMove({x: 50, y: 0}).mouseUp().perform();
        });
      });
    });
    

    【讨论】:

    • 快速说明:Actions API 已更改/即将更改。此声明基于库或浏览器驱动程序是否已实现 W3C 操作标准。 Protractor 目前正在使用 selenium-webdriver 3(W3C 之前的标准),一些浏览器驱动程序(如 gecko)可能无法正常工作(使用 W3C 标准)
    • @Saddam 它不工作,它有一个错误:“失败:10069 毫秒后等待超时”
    • @SeanRay 您提到超时 10 秒(即 10000 毫秒)的代码失败。这就是为什么它显示该错误。此外,如果在 5 秒内浏览器中不存在 whiteBox 元素,我的代码可能会引发类似的错误,即 "Failed:Wait timed out after 5000ms"
    • @SeanRay,你的意思是你想改变一些输入文本框的值?
    • @SaddamPojee 我已经弄清楚如何移动方框,但我还需要更改文本上的值。 ['code'] browser.wait(EC.presenceOf(whiteBox), 5000).then(() => { whiteBox.getAttribute('transform').then(() =>{ browser.driver.executeScript("document .getElementById('IndicateNav').setAttribute('transform','translate(600)')"); }); ['code']
    猜你喜欢
    • 2019-08-11
    • 2019-04-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-10-24
    • 2018-01-04
    相关资源
    最近更新 更多