问题
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'.
回答1:
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.
回答2:
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
来源:https://stackoverflow.com/questions/57878473/i-cant-create-filter-to-extract-all-elements-that-i-need