void () { final XmlFile file = (XmlFile)PsiFileFactory.getInstance(getProject()) .createFileFromText("test.xml", "<a>\n <a>\n <b>\n hasgdgasjdgasdg asgdjhasgd</b>\n </a>\n</a>"); final XmlTag tagB = file.getDocument().getRootTag(); WriteCommandAction.runWriteCommandAction(null, () -> tagB.getSubTags()[0].getSubTags()[0].delete()); assertEquals("<a>\n <a>\n </a>\n</a>", tagB.getText()); }