我找不到正确的元素 [英] I can't get right elements

查看:106
本文介绍了我找不到正确的元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我单击排序按钮,获取所有价格,并且我需要确保元素按价格正确排序。因此,我需要获取价格值= 377,价格值= 1288,价格值= 1688等,但我无法获取正确的元素。

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>

我尝试搜索CSS,className,xpath,repearet,我想它们是否都是相同的转发器会工作。
我的代码:

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)

我需要仅获得价格,例如 3.77, 12.88, 16.88等,然后验证它们是否为ASC排序,但我得到了所有价格,甚至是旧价格。我只需要获取

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

预计['$ 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]为 smth。
堆栈:

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:

推荐答案

从提供的HTML看来,它类似于CSS选择器 div。 ssl-price-box> price 将为您提供所需的所有价格要素。从那里,您可以使用 .getAttribute () 从每个元素中将 value 属性提取为 377, 1288等。然后,您需要将这些字符串值转换为数字复制该数组对第二个数组进行排序,然后比较第一个列表,以验证两个列表是否已排序。

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.

这篇关于我找不到正确的元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆