我无法创建过滤器来提取我需要的所有元素 [英] I can't create filter to extract all elements that i need

查看:95
本文介绍了我无法创建过滤器来提取我需要的所有元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

即使我不需要价格,我也能得到价格,如何过滤呢?

I get prices, even that I don't need, how can I filter them?

<div class="ssl-price-box">
    <price value="377" units="/yr" class="lg-price ng-isolate-scope"><span class="price"><span class="currency-icon">$</span><span class="integer ng-binding">3.</span><span class="cent ng-binding">77</span><span class="units">/yr</span></span></price>
<!-- ngIf: product.prices.max.certIsPromo -->
</div>   

 <price value="13888" units="/yr" class="lg-price ng-isolate-scope">
        <span class="price">
            <span class="currency-icon">$</span>
            <span class="integer ng-binding">138.</span>
            <span class="cent ng-binding">88</span>
            <span class="units">/yr</span>
        </span>
    </price>

<price ng-if="product.prices.max.certIsPromo" value="21589" units="/yr" old-price="" class="base-price ng-scope ng-isolate-scope">
    <span class="price old-price">
        <span class="currency-icon">$</span>
        <span class="integer ng-binding">215.</span>
        <span class="cent ng-binding">89</span>
        <span class="units">/yr</span>
        <span class="line-through"></span>
    </span>
</price>

我不知道该怎么做.我尝试过

I have no idea how to do it. I tried

const allSSLList = element.all(by.css('div.ssl-price-box')).all(by.className("span[class='price']"));

还有这个

const allSSLList = element.all(by.css('div.ssl-price-box > price'));
expect(await allSSLList)).toBe(newPrices)

我拥有所有元素,但不需要第二个CSS中的class class ="price old-price"中的旧价格,因为我需要将Array与所有新价格进行比较

I got all elements, but I don't need old price in tag class="price old-price" from second css, because I need compare Array with all new prices

预期['377','1288','2699','1688','3199','1966','3588','3088','4499','3888','9599',' 5999","6888","13899","7088","9699","7819","7819","13499","13888","21589"]为"newPrice".

Expected [ '377', '1288', '2699', '1688', '3199', '1966', '3588', '3088', '4499', '3888', '9599', '5999', '6888', '13899', '7088', '9699', '7819', '7819', '13499', '13888', '21589' ] to be 'newPrice'.

推荐答案

使用提供的HTML,您似乎可以使用XPath

With the HTML provided, it looks like you can use the XPath

//div[@class='ssl-price-box']/price[not(@old-price)]
^ find a DIV that has the right class
                             ^ find a child PRICE tag
                                   ^ that does not contain the attribute "old-price"

仅获得不是旧价格的价格.从那里,您可以使用 .getAttribute() 来从每个元素中将value属性拉为"377","1288"等.

to only get the price that aren't old prices. From there, you can use .getAttribute() to pull the value attribute from each element as "377", "1288", etc.

这篇关于我无法创建过滤器来提取我需要的所有元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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