我在柏树工作。重现的步骤
我只是通过cy.visit()访问登录页面--Spinner正在加载传递凭据使用type-spinner仍然加载点击提交。-spinner仍在加载其抛出错误..为什么因为登录页面XHR调用没有完成多数民众赞成为什么我们仍然可以看到微调器加载在顶部,我试图在加载之前单击提交按钮,可能是因为网络告知无效的凭据。
我相信您必须等待XHR请求完成并验证页面加载或执行其他操作。
这是一个样本,
// Wait for the route aliased as 'getAccount' to respond
cy.server()
cy.route('/accounts/*').as('getAccount')
cy.visit('/accounts/123')
cy.wait('@getAccount').then((xhr) => {
cy.get('#loading-bar').should('not.be.visible')
})
这是我之前给出的类似解决方案 - Cypress:Is there any way to check invisibility of an element
检查按钮是否存在,然后单击按钮。如果
describe('check if button present', function () {
it('check for button using CSS Selector', function () {
cy.visit(url)
let found = false
let count=0
while (!found) {
const nonExistent = Cypress.$('.btn-selector')
if (!nonExistent.length) {
found = false
count=count+1
cy.wait(1000)
if(count==60)
{
found = true
cy.log('Element not found after 60 seconds..Exit from loop!!!')
}
}
else
{
found = true
cy.get('.btn-selector').click()
}
}
})
})