void () { String text = """ <html> <ul class="dropdown-menu"> <li><a href="#">One more separated link</a></li> </ul> <caret> </html>"""; final PsiFile file = configureByText(XmlFileType.INSTANCE, text ); final XmlTag ul = PsiTreeUtil.getParentOfType(file.findElementAt(file.getText().indexOf("ul")), XmlTag.class); assertNotNull(ul); assertEquals("ul", ul.getName()); assertEquals("dropdown-menu", ul.getAttributeValue("class")); SmartPsiElementPointer<XmlTag> ulPointer = createPointer(ul); WriteCommandAction.runWriteCommandAction(getProject(), () -> { int offset = getEditor().getCaretModel().getOffset(); insertString(getEditor().getDocument(), offset, """ <ul class="nav navbar-nav navbar-right"> </ul> """); }); PsiDocumentManager.getInstance(getProject()).commitAllDocuments(); final XmlTag newUl = ulPointer.getElement(); assertNotNull(newUl); assertEquals("ul", newUl.getName()); assertEquals("dropdown-menu", newUl.getAttributeValue("class")); }