如何在testcafe中获取标签的css属性?

如何在testcafe中获取标签的css属性?,css,automated-tests,e2e-testing,web-testing,testcafe,Css,Automated Tests,E2e Testing,Web Testing,Testcafe,我有一个简单的代码,其结构如下: <div> <style>label { property: value; }</style> <label id="id1">text</label> </div> 但是,它总是返回未定义的值,是否有我遗漏的内容?您可能遗漏了waitbeforeSelector,所以它应该是 const sel=wait Selector('#id1')。getStyleProperty('pr

我有一个简单的代码,其结构如下:

<div>
  <style>label { property: value; }</style>
  <label id="id1">text</label>
</div>

但是,它总是返回未定义的值,是否有我遗漏的内容?

您可能遗漏了
wait
before
Selector
,所以它应该是

const sel=wait Selector('#id1')。getStyleProperty('property')


关于缺少的
wait
,你说得很对,但还有一句话。如果要计算选择器的属性值并将结果赋给变量,请使用以下代码:
const sel=wait Selector('#id1')。getStyleProperty('property')
但是如果不需要保存属性的值并且只需要在断言中使用它,可以省略
await
语句来使用
await t.expect(选择器('#id1').getStyleProperty('property')).eql(propertyValue)
const sel=Selector('#id1').getStyleProperty('property');wait t.expect(sel).eql(propertyValue)
const sel = Selector('#id1').getStyleProperty('property')
const sel = Selector('#id1').getStyleProperty('property')
await t.expect(await sel).eql(propertyValue)