CypressError:cy.click() 失败,因为该元素被另一个元素覆盖

Dan*_*iel 8 cypress

因此,我尝试运行 Cypress 测试,用户进入右上角的下拉菜单,单击“我的设置”,然后单击一个名为“隐私政策”的链接:

it.only('2.5 - Press "Privacy Policy" on the "My Settings" screen. - "Armadillo Privacy Policy" screen is displayed', () => {
  cy.login()

  cy.get('body div button[data-cy=usermenubutton]')
    .click()
    .get('body div ul li[data-cy=mySettings]')
    .contains('My Settings')
    .click()

  cy.get('a[href="/legal/privacy"]')
    .click()

  cy.screenshot()
})
Run Code Online (Sandbox Code Playgroud)

但是,无论我如何重构,我仍然会收到此错误:

cy.click() failed because this element:

<a class='MuiTypography-root-bwkfm MuiTypography-root MuiTypography-inherit MuiTypography-root-dfghjk MuiLink-root MuiLink-underlineAlways" href="/legal/privacy">Privacy...</a>

is being covered by another element:

<div aria-hidden="true" class="MuiBackdrop-root-fghjkl hjk MuiBackdrop-root MuiBackdrop-invisible MuiModal-backdrop-klghjkhg tyutyu style="opacity: 1; transition: opacity 225ms cubic-bezier(0.4, 0, 0.2, 1) 0ms;"></div>

Fix this problem, or use {force: true} to disable error checking.
Run Code Online (Sandbox Code Playgroud)

Ala*_*Das 9

由于您的元素被另一个元素覆盖,因此您可以使用click({force: true}), 禁用错误检查并执行单击。

cy.get('a[href="/legal/privacy"]').click({force: true})
Run Code Online (Sandbox Code Playgroud)

  • 这只是停止错误,但点击对我不起作用。 (3认同)