use of com.gargoylesoftware.htmlunit.html.parser.neko.HtmlUnitNekoHtmlParser in project faces by jakartaee.
the class Spec1555IT method addValueAttribute.
/**
* HtmlUnit's HtmlFileInput doesn't support submitting multiple values.
* The below is a work-around, found on https://stackoverflow.com/a/19654060
*/
private static void addValueAttribute(HtmlFileInput input, String valueAttribute) {
AttributesImpl attributes = new AttributesImpl();
attributes.addAttribute(null, null, "type", null, "file");
attributes.addAttribute(null, null, "name", null, input.getNameAttribute());
HtmlFileInput cloned = (HtmlFileInput) new HtmlUnitNekoHtmlParser().getFactory("input").createElementNS(input.getPage(), null, "input", attributes);
input.getParentNode().appendChild(cloned);
cloned.setValueAttribute(valueAttribute);
}
use of com.gargoylesoftware.htmlunit.html.parser.neko.HtmlUnitNekoHtmlParser in project posters-advanced-loadtest-suite by Xceptance.
the class DOMUtils method replaceElement.
/**
* Replaces a full element
*
* @param container
* the element to replace
* @param content
* the cotnent to parse in
*/
public static HtmlElement replaceElement(final HtmlElement container, final String content) {
Assert.assertNotNull("Container most not be null", container);
try {
// create a temporary container to parse the new content into
final HtmlElement tmp = HtmlPageUtils.createHtmlElement("div", Page.getBody());
new HtmlUnitNekoHtmlParser().parseFragment(tmp, content);
// ok, if we have more than on child in our tmp node, we cannot simply replace
// the container, because that is not possible, hence we complain
Assert.assertTrue("You can only replace a node with a single node.", tmp.getChildElementCount() == 1);
final DomElement child = tmp.getChildElements().iterator().next();
container.replace(child);
// and erase the temporary container
tmp.remove();
return (HtmlElement) child;
} catch (SAXException | IOException e) {
// let's not discuss the details, we got a problem
throw new AssertionError(e.getMessage(), e);
}
}
Aggregations