MCPcopy Create free account
hub / github.com/HtmlUnit/htmlunit / setTitleText

Method setTitleText

src/main/java/org/htmlunit/html/HtmlPage.java:1170–1190  ·  view source on GitHub ↗

Sets the text for the title of this page. If there is not a title element on this page, then one has to be generated. @param message the new text

(final String message)

Source from the content-addressed store, hash-verified

1168 * @param message the new text
1169 */
1170 public void setTitleText(final String message) {
1171 HtmlTitle titleElement = getTitleElement();
1172 if (titleElement == null) {
1173 LOG.debug("No title element, creating one");
1174 final HtmlHead head = (HtmlHead) getFirstChildElement(getDocumentElement(), HtmlHead.class);
1175 if (head == null) {
1176 // perhaps should we create head too?
1177 throw new IllegalStateException("Headelement was not defined for this page");
1178 }
1179 final Map<String, DomAttr> emptyMap = Collections.emptyMap();
1180 titleElement = new HtmlTitle(HtmlTitle.TAG_NAME, this, emptyMap);
1181 if (head.getFirstChild() != null) {
1182 head.getFirstChild().insertBefore(titleElement);
1183 }
1184 else {
1185 head.appendChild(titleElement);
1186 }
1187 }
1188
1189 titleElement.setNodeValue(message);
1190 }
1191
1192 /**
1193 * Gets the first child of startElement that is an instance of the given class.

Callers 1

setTitleMethod · 0.80

Calls 8

getTitleElementMethod · 0.95
getFirstChildElementMethod · 0.95
getDocumentElementMethod · 0.95
setNodeValueMethod · 0.95
debugMethod · 0.65
getFirstChildMethod · 0.45
insertBeforeMethod · 0.45
appendChildMethod · 0.45

Tested by

no test coverage detected