1

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']"));

and this

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

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

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

Max Volobuev
  • 79
  • 2
  • 11
  • Can you please share the html of `div.ssl-price-box`, so that we can provide the right answer. – supputuri Sep 10 '19 at 23:29
  • update description. i need combine queries: element(by.css('ssl-price-box')).all(by.xpath('//price[not(@old-price)]')); because first part of the query doesn't work and i get not only from ssl-price-box but from others div too – Max Volobuev Sep 11 '19 at 10:15
  • Possible duplicate of [I can't get right elements](https://stackoverflow.com/questions/57873506/i-cant-get-right-elements) – Joaquin Casco Sep 11 '19 at 11:30
  • it is different problems, but the are around one case)) – Max Volobuev Sep 11 '19 at 12:03

2 Answers2

1

allSSLList will return an array with all the prices, as you are getting inside the expectation. You need to specify which element from the array you want with a .get(index);

But please provide more info because from the html snipped it's not clear exactly what element do you need to retrieve

Joaquin Casco
  • 704
  • 5
  • 14
0

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"

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.

JeffC
  • 22,180
  • 5
  • 32
  • 55
  • the last question, how i can combine queries: element(by.css('ssl-price-box')).all(by.xpath('//price[not(@old-price)]')); because first part of the query doesn't work and i get not only from ssl-price-box. i updated main description – Max Volobuev Sep 11 '19 at 10:12
  • I updated the answer. See if that's what you are looking for. – JeffC Sep 11 '19 at 13:42