void () { String html = "<html><head /><body><hr /></body>\n</html>"; XmlFile file = (XmlFile)PsiFileFactory.getInstance(getProject()).createFileFromText("a.html", HtmlFileType.INSTANCE, html); XmlTag body = file.getDocument().getRootTag().findFirstSubTag("body"); XmlTag hr = body.getSubTags()[0]; XmlText text = XmlElementFactory.getInstance(getProject()).createDisplayText("p"); PsiElement element = body.addAfter(text, hr); assertEquals(body, element.getParent()); }