如何从赛普拉斯的属性选项卡中调用或获取子 属性 值
how to invoke or get the sub-property value from Properties Tab in cypress
如何从属性选项卡调用子 属性 值。我需要从“属性”选项卡
中获取 error.JPG
的值
我尝试了这些不同的代码更改
cy.get('div [data-text-as-pseudo-element="error.JPG"]').invoke('prop','dataset').should('contain','error.JPG')
cy.get('div [data-text-as-pseudo-element="error.JPG"]').invoke('prop','dataset').should('contain','DOMStringMap')
cy.get('[data-text-as-pseudo-element="error.JPG"]').invoke('prop', 'dataset').then(dataset,()=>{
cy.wrap(dataset).invoke('prop','textAsPseudoElement').should('contain','error.JPG')
})
我收到断言错误
Timed out retrying after 4000ms: object tested must be an array, a map, an object, a set, a string, or a weakset, but domstringmap given
The dataset read-only property of the HTMLElement interface provides read/write access to custom data attributes (data-*)
on elements. It exposes a map of strings (DOMStringMap) with an entry for each data-*
attribute.
您的 Cypress 测试可以将其视为常规属性
cy.get('my-selector')
.should('have.attr', 'data-text-as-pseudo-element', 'error.JPG')
你上面提出的测试已经完成了
cy.get('div[data-text-as-pseudo-element="error.JPG"]')
因为浏览器保证属性会添加到dataset
。
如果您想进一步使用 Javascript 中的数据集,只需链接属性,例如
cy.get('div[data-text-as-pseudo-element="error.JPG"]')
.should($el => {
const attrValue = $el[0].dataset.textAsPseudoElement
expect(attrValue).to.eq('error.JPG')
})
如何从属性选项卡调用子 属性 值。我需要从“属性”选项卡
中获取error.JPG
的值
我尝试了这些不同的代码更改
cy.get('div [data-text-as-pseudo-element="error.JPG"]').invoke('prop','dataset').should('contain','error.JPG')
cy.get('div [data-text-as-pseudo-element="error.JPG"]').invoke('prop','dataset').should('contain','DOMStringMap')
cy.get('[data-text-as-pseudo-element="error.JPG"]').invoke('prop', 'dataset').then(dataset,()=>{
cy.wrap(dataset).invoke('prop','textAsPseudoElement').should('contain','error.JPG')
})
我收到断言错误
Timed out retrying after 4000ms: object tested must be an array, a map, an object, a set, a string, or a weakset, but domstringmap given
The dataset read-only property of the HTMLElement interface provides read/write access to custom data attributes
(data-*)
on elements. It exposes a map of strings (DOMStringMap) with an entry for eachdata-*
attribute.
您的 Cypress 测试可以将其视为常规属性
cy.get('my-selector')
.should('have.attr', 'data-text-as-pseudo-element', 'error.JPG')
你上面提出的测试已经完成了
cy.get('div[data-text-as-pseudo-element="error.JPG"]')
因为浏览器保证属性会添加到dataset
。
如果您想进一步使用 Javascript 中的数据集,只需链接属性,例如
cy.get('div[data-text-as-pseudo-element="error.JPG"]')
.should($el => {
const attrValue = $el[0].dataset.textAsPseudoElement
expect(attrValue).to.eq('error.JPG')
})