如何通过文本查找元素?

new9mtju  于 2021-09-13  发布在  Java
关注(0)|答案(0)|浏览(219)

如果在网站中有“立即设计”按钮或找到h1标签,仍然会转到“其他”部分。
html代码

<main>
  <h1>Return dynamic status code</h1>
  <p>"Off-the-shelf products" are not your thing. Then just design your own.</p>
  <a class="btn btn-secondary" href="/steps">Design Now</a>
</main>

我的代码

// By design now button
    cy.get('body').then((body) => {
        if (body.find('.btn-secondary').contains('Design Now').length > 0) {
            cy.log('Return dynamic status code')
        } else {
            cy.log('remove products')
            s2.productlist().find('.close-img').then(($ele) => {
                cy.get($ele).click({ multiple: true, force: true })
            })
        }
    })

    // by h1 text
    cy.get('body').then((body) => {
        if (body.find('h1').text('Return dynamic status code').length > 0) {
            cy.log('Return dynamic status code')
        } else {
            cy.log('remove products')
            s2.productlist().find('.close-img').then(($ele) => {
                cy.get($ele).click({ multiple: true, force: true })
            })
        }
    })

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题