0

I click the sort button, get all prices, and I need to ensure that elements were sorted correctly by prices. So I need to get price value="377", price value="1288", price value="1688" etc. but I can't get the right elements.

<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>
<div class="ssl-content">
    <div class="ssl-price-box">
        <price value="1288" units="/yr" class="lg-price ng-isolate-scope">
            <span class="price">
                <span class="currency-icon">$</span>
                <span class="integer ng-binding">12.</span>
                <span class="cent ng-binding">88</span>
                <span class="units">/yr</span>
            </span>
        </price>

i tried search be css, className, xpath, repearet, i thought if they are all the same repeater would work. My code:

const allSSLList = $$('.ssl-price-box');
const newAllSSLList = allSSLList.sort((a, b)=>a-b));

expect(await allSSLList).toBe(massiveOfElements)

I need to get only prices, e.g. "3.77", "12.88", "16.88" etc. and then verify if they are ASC sorting but I got all prices, even old ones. I need to get only where

<span class="price">
    <price value="377" units="/yr" class="lg-price ng-isolate-scope">

Expected [ '$3.77/YR', '$12.88/YR $26.99/YR', '$16.88/YR $31.99/YR', '$19.66/YR $35.88/YR', '$30.88/YR $44.99/YR', '$38.88/YR $95.99/YR', '$59.99/YR', '$68.88/YR $138.99/YR', '$70.88/YR $96.99/YR', '$78.19/YR', '$78.19/YR', '$134.99/YR', '$138.88/YR $215.89/YR' ] to be 'smth'. Stack:

JeffC
  • 22,180
  • 5
  • 32
  • 55
Max Volobuev
  • 79
  • 2
  • 11
  • You are using incorrect locators. Your DOM doesn't have any 'ng-app' – work_ishaan Sep 10 '19 at 15:59
  • what locator should i use? – Max Volobuev Sep 10 '19 at 16:42
  • I would say the question is too broad. This is why here is my broad answer - assign elementArrauyFinder to a variable, that points to all elements you need (you may check it in browser's devtools), `.getText()` of it OR `.getAttribute("attribute")` whichever you need, and only then you can sort these values and compare if sorted array matches unsorted – Sergey Pleshakov Sep 10 '19 at 20:03
  • thanks, first o f all i need extract correct data, because i get all prices, even that i don't need, i describe the problem below, thank you! – Max Volobuev Sep 10 '19 at 21:09

1 Answers1

0

From the HTML provided, it looks like the CSS selector div.ssl-price-box > price will get you all the price elements you need. From there, you can use .getAttribute() to pull the value attribute from each element as "377", "1288", etc. Then you would want to convert those string values into numbers, copy that array, sort the second array, and then compare to the first list to verify that the two lists are sorted.

JeffC
  • 22,180
  • 5
  • 32
  • 55
  • Thank you! I did everything that you wrote element.all(by.css('div.ssl-price-box > price')); but i get result not ONLY from , but from $215.89/yr do i need a filter? – Max Volobuev Sep 10 '19 at 21:06
  • Which prices do you NOT want? Please update your question with the HTML of prices that you do want and then give an example of a price that you don't want. From there we should be able to come up with a locator that filters out the ones you don't want. – JeffC Sep 10 '19 at 21:39
  • i create new problem, i think it will be easier https://stackoverflow.com/questions/57878473/i-cant-create-filter-to-extract-all-elements-that-i-need – Max Volobuev Sep 10 '19 at 22:02