use of com.gargoylesoftware.htmlunit.html.DomText in project htmlunit by HtmlUnit.
the class HTMLElement method setTextContent.
/**
* Replaces all child elements of this element with the supplied text value.
* @param value the new value for the contents of this element
*/
@Override
public void setTextContent(final Object value) {
final DomNode domNode = getDomNodeOrDie();
domNode.removeAllChildren();
if (value != null) {
final String textValue = Context.toString(value);
if (StringUtils.isNotEmpty(textValue)) {
domNode.appendChild(new DomText(domNode.getPage(), textValue));
}
}
}
use of com.gargoylesoftware.htmlunit.html.DomText in project htmlunit by HtmlUnit.
the class HTMLScriptElement method setText.
/**
* Sets the {@code text} property.
* @param text the {@code text} property
*/
@JsxSetter
public void setText(final String text) {
final HtmlElement htmlElement = getDomNodeOrDie();
htmlElement.removeAllChildren();
final DomNode textChild = new DomText(htmlElement.getPage(), text);
htmlElement.appendChild(textChild);
ScriptElementSupport.executeScriptIfNeeded(htmlElement, false, false);
}
use of com.gargoylesoftware.htmlunit.html.DomText in project htmlunit by HtmlUnit.
the class HTMLScriptElement method getText.
/**
* Returns the {@code text} property.
* @return the {@code text} property
*/
@JsxGetter
public String getText() {
final StringBuilder scriptCode = new StringBuilder();
for (final DomNode node : getDomNodeOrDie().getChildren()) {
if (node instanceof DomText) {
final DomText domText = (DomText) node;
scriptCode.append(domText.getData());
}
}
return scriptCode.toString();
}
use of com.gargoylesoftware.htmlunit.html.DomText in project htmlunit by HtmlUnit.
the class HTMLOptionElement method jsConstructor.
/**
* JavaScript constructor.
* @param newText the text
* @param newValue the value
* @param defaultSelected Whether the option is initially selected
* @param selected the current selection state of the option
*/
@JsxConstructor({ CHROME, EDGE, FF, FF_ESR })
public void jsConstructor(final Object newText, final String newValue, final boolean defaultSelected, final boolean selected) {
final SgmlPage page = (SgmlPage) getWindow().getWebWindow().getEnclosedPage();
AttributesImpl attributes = null;
if (defaultSelected) {
attributes = new AttributesImpl();
attributes.addAttribute(null, "selected", "selected", null, "selected");
}
final HtmlOption htmlOption = (HtmlOption) page.getWebClient().getPageCreator().getHtmlParser().getFactory(HtmlOption.TAG_NAME).createElement(page, HtmlOption.TAG_NAME, attributes);
htmlOption.setSelected(selected);
setDomNode(htmlOption);
if (!Undefined.isUndefined(newText)) {
final String newTextString = Context.toString(newText);
htmlOption.appendChild(new DomText(page, newTextString));
htmlOption.setLabelAttribute(newTextString);
}
if (!"undefined".equals(newValue)) {
htmlOption.setValueAttribute(newValue);
}
}
use of com.gargoylesoftware.htmlunit.html.DomText in project htmlunit by HtmlUnit.
the class GWT250Test method assertElementValue.
/**
* Test value inside {@link HtmlDivision}, {@link HtmlInput} or {@link DomText}
*
* @param element the element to search in
* @param expectedValue expected value of the value inside the cell
*/
private static void assertElementValue(final HtmlElement element, final String expectedValue) {
DomNode child = element.getFirstChild();
while (child != null && !(child instanceof DomElement) && (!(child instanceof DomText) || !((DomText) child).getData().equals(expectedValue))) {
child = child.getNextSibling();
}
if (child instanceof HtmlDivision) {
final HtmlDivision div = (HtmlDivision) child;
DomNode firstChild = div.getFirstChild();
while (firstChild != null && !(firstChild instanceof DomElement)) {
firstChild = firstChild.getNextSibling();
}
if (firstChild instanceof HtmlBold || firstChild instanceof HtmlItalic) {
firstChild = firstChild.getFirstChild();
}
if (firstChild instanceof DomText) {
final DomText text = (DomText) firstChild;
assertEquals(expectedValue, text.getData());
} else {
fail("Could not find '" + expectedValue + "'");
}
} else if (child instanceof HtmlInput) {
final HtmlInput input = (HtmlInput) child;
assertEquals(expectedValue, input.getValueAttribute());
} else if (child instanceof DomText) {
final DomText text = (DomText) child;
assertEquals(expectedValue, text.getData());
} else {
fail("Could not find '" + expectedValue + "'");
}
}
Aggregations