量角器无法移动价格滑块 [英] Protractor not able to move price slider

查看:43
本文介绍了量角器无法移动价格滑块的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是量角器的新手,试图测试可以根据提供的价格范围对产品进行排序的价格滑块,我无法使用量角器拖动滑块(最小点).如何移动滑块?

I am new to protractor, trying to test price slider which may sort products based on provided price range, i could not able to drag the slider(min point) using protractor. how to move the slider?

HTML

<span _ngcontent-serverapp-c119="" ngxsliderhandle="" class="ngx-slider-span ngx-slider-pointer ngx-slider-pointer-min" ng-reflect-ng-style="[object Object]" role="slider" tabindex="0" aria-orientation="" aria-label="" aria-labelledby="" aria-valuenow="10" aria-valuetext="10" aria-valuemin="10" aria-valuemax="100" style="opacity: 1; visibility: visible; left: 0px;"></span>

滑块图片

我试过

    const priceTogggle = element(
        by.xpath(
            '//span[@class="ngx-slider-span ngx-slider-pointer ngx-slider-pointer-min"]'
        )
    );

browser.actions().dragAndDrop(priceTogggle,{x:100,y:0}).mouseUp().perform();  
and   
browser.actions().mouseMove(priceTogggle).mouseDown().mouseMove({x:100,y:0 }).mouseUp().perform()

推荐答案

这是我用的

     /**
     * Drags first element to the second one. The destination can either be an elementFinder or an offset in pixels
     * @param    {ElementFinder}        $element
     * @param    {(ElementFinder|{x: number, y: number})}       $destination
     * @returns  {promise.Promise}
     */
    let dragAndDrop = ($element, $destination) => browser
            .actions()
            .mouseMove($element)
            .perform()
            .then(() =>
                browser
                    .actions()
                    .mouseDown($element)
                    .perform()
            )
            .then(() =>
                browser
                    .actions()
                    .mouseMove($destination)
                    .perform()
            )
            .then(() =>
                browser
                    .actions()
                    .mouseUp()
                    .perform()
            );

然后调用

await dragAndDrop($leftGrip, {x: 10, y: 0});

但是 x 可能需要为负数,具体取决于您要移动的方向

But x might need to be negative depending on direction you're moving to

这篇关于量角器无法移动价格滑块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆