HTML is notoriously difficult to parse and it has usually been a pain to do this in Java. Yes I know that there are parsers (like jtidy and nekohtml) that try to create a proper DOM but I’ve been waiting for something more lightweight.
Enter Jsoup. It feels like a mix of JQuery and Beautiful Soup (for Python).
String html = response.getContentAsString();
Document document = Jsoup.parse(html);
Elements elements = document.select("#errorRef");
assertThat(elements.size(), equalTo(1));
assertThat(elements.first().text(), equalTo(errorRef));
Mmm, full flavour, none of the fat.