TestCafe-在下拉列表中获取属性的值

问题描述 投票:0回答:1

[带有一个用于过滤的按钮的搜索栏。单击同一子菜单(下拉菜单)。 HTML看起来像:

<ul >
  <li data-value"svalue1">
     <svg>.... </svg>
     <p> Value1 </p>
  </li>
  <li data-value"svalue2">
     <svg> ....</svg>
     <p> Value2 </p>
  </li>
  <li data-value"svalue3">
     <svg> </svg>
     <p> Value3 </p>
  </li>

我需要将options的值作为数组进行检索并进行比较。我能够断言一个值,但无法将其存储在数组中以将所有值进行比较。

var tab = Selector('ul');
-
-
.expect(tab.child('li').nth(3).innerText)
            .eql('Value3', 'The value is not correct');

但是这不起作用

for (let i = 0; i < 6; i++) {
                myArray.push(tab.child('li').nth(i).innerText);
                console.log("value:" + tab.child('li').nth(i).innerText);

            }

Prints: value:[object Object]

任何想法?

dropdown testcafe
1个回答
0
投票

您需要添加'await'关键字。例如:

for (let i = 0; i < 6; i++) {
   console.log("value:" + await tab.child('li').nth(i).innerText);
}

请参考'Access Page Element Properties'主题以找到此注释:

Note that selector's property getters and client functions are asynchronous. If you need their resulting value in your code, use the await keyword. However, you can omit await when you pass a selector property or a client function value into an assertion.

© www.soinside.com 2019 - 2024. All rights reserved.