我无法创建过滤器来提取我需要的所有元素

I can't create filter to extract all elements that i need

我得到价格,即使我不需要,我如何过滤它们?

<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>

我不知道该怎么做。我试过了

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="price old-price" 中的旧价格,因为我需要将数组与所有新价格进行比较

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

allSSLList 将 return 包含所有价格的数组,因为您正在进入预期。您需要使用 .get(index);

指定您想要的数组中的哪个元素

但请提供更多信息,因为从 html 片段中不清楚您到底需要检索什么元素

有了提供的HTML,看来你可以使用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”等。