Search in sources :

Example 1 with HtmlUnitNekoHtmlParser

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);
}
Also used : AttributesImpl(org.xml.sax.helpers.AttributesImpl) HtmlUnitNekoHtmlParser(com.gargoylesoftware.htmlunit.html.parser.neko.HtmlUnitNekoHtmlParser) HtmlFileInput(com.gargoylesoftware.htmlunit.html.HtmlFileInput)

Example 2 with HtmlUnitNekoHtmlParser

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);
    }
}
Also used : DomElement(com.gargoylesoftware.htmlunit.html.DomElement) HtmlElement(com.gargoylesoftware.htmlunit.html.HtmlElement) HtmlUnitNekoHtmlParser(com.gargoylesoftware.htmlunit.html.parser.neko.HtmlUnitNekoHtmlParser) IOException(java.io.IOException) SAXException(org.xml.sax.SAXException)

Aggregations

HtmlUnitNekoHtmlParser (com.gargoylesoftware.htmlunit.html.parser.neko.HtmlUnitNekoHtmlParser)2 DomElement (com.gargoylesoftware.htmlunit.html.DomElement)1 HtmlElement (com.gargoylesoftware.htmlunit.html.HtmlElement)1 HtmlFileInput (com.gargoylesoftware.htmlunit.html.HtmlFileInput)1 IOException (java.io.IOException)1 SAXException (org.xml.sax.SAXException)1 AttributesImpl (org.xml.sax.helpers.AttributesImpl)1