简体   繁体   中英

Is {force: true} the only way for invisible elements in Cypress?

Is there any alternative way apart from {force: true} on click & type function for the elements not visible in the web application using Cypress?

Using {force:true} on each & every function doesn't seem to be an ideal way. Any thoughts team?

You can use .should('be.visible') like:

cy.get('#element-id').should('be.visible').click()

You can use .wait() like:

cy.get('#element-id').wait(2000).should('be.visible').click()

You can use .then() like;

cy.get('#element-id').then(($el) => {
    if ($el.is(':visible')) {
        $el.click()
    }
})

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM