Can I remove a HTML element using Cypress?

Viewed 1114

Is it possible to use Cypress to find and delete an element from the HTML? And how to do it?

Edit: This works:

cy.get(selector).then((elem) => {
  const elemHtml = elem.get(0)
  elemHtml.remove()
})
2 Answers

get() yields the DOM element(s) it found which can then be removed.

cy.get(selector).then($el => $el.remove());

You can use embedded jquery in cypress:

Cypress.$(yourElementSelector).remove();
Related