问题
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:
回答1:
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.
来源:https://stackoverflow.com/questions/57873506/i-cant-get-right-elements