首页 > 解决方案 > Cypress - 停止下一页导航

问题描述

假设我知道下一页导航的 URL,有没有办法阻止下一个操作执行导航,无论导航是由 href 还是 js 引导的?试过cy.intercept不行。

// doesn't work
cy.intercept({ hostname: 'cross.domain' }, (req) => {})
cy.contains('Next').click()

标签: cypress

解决方案


您可以使用JQ .attr()


    cy.get(`aTagSelector`) //This part is recommended to check if you click the required button with the link to cross origin
        .should('have.attr', 'href')
        .and('include', `expectedUrl`)
    cy.get(`aTagSelector`)
        .then($aTagElement => {
            $aTagElement.attr("href", '/');
            cy.get($aTagElement)
                .click({force: true})
        })

推荐阅读