简单的问题。例如,我如何测试(使用cypress
)我使用 css 选择器查询的元素是 a h2
?
cy.get('.qards-widget-hero').first()// this needs to be a h2
@Maccurt 的答案适用于所选类没有其他元素的情况,但如果存在以下情况,则测试将报告误报。
<h1 class="qards-widget-hero"></h1>
<h2 class="qards-widget-hero"></h2>
Run Code Online (Sandbox Code Playgroud)
请参阅此问题如何使用 chai 检查元素类型。
我想你可以使用类似的东西
cy.get('.qards-widget-hero').first()
.should('have.prop', 'tagName' ).should('eq', 'H2') // tagName is uppercase
Run Code Online (Sandbox Code Playgroud)
您能给我们看一下所有 HTML 的片段吗?
如果我正确地阅读了你的问题,你想确保 h2 存在。你说需要是一个h2,我认为存在会做同样的事情。我假设这个小部件是 h2 并且具有 qards-widget-hero 类。
cy.get('h2.qards-widget-hero').should('exist')
Run Code Online (Sandbox Code Playgroud)
//如果你想要第一个
cy.get('h2.qards-widget-hero').first().should('exist')
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
7537 次 |
最近记录: |