【发布时间】:2020-08-08 14:51:08
【问题描述】:
我需要获取 data-id 的值,但是当我使用下面的代码时它没有返回任何值。
cy.get('[data-nemo=token]')
.invoke('attr', 'data-id').then(dataId => {
cy.log('dataId : ', dataId);`enter code here`
});
谢谢,
【问题讨论】:
-
看起来
invoke()的使用不当。据我从文档中可以看出,它应该类似于cy.get('[data-nemo=token]').getAttribute('data-id')。相关文档:docs.cypress.io/api/commands/get.html#Selector使用 .getAttribute 时出现错误 - TypeError: cy.get(...).getAttribute() is not a function页面上有多少元素匹配该选择器?如果get()返回一个类似对象的数组,您将不得不深入研究如何让元素调用getAttributeonstackoverflow.com/questions/51178736/… 哇,invoke()的事情我可能完全错了。
标签: jquery attributes cypress invoke