Search in sources :

Example 1 with HtmlLabel

use of com.gargoylesoftware.htmlunit.html.HtmlLabel in project htmlunit by HtmlUnit.

the class HTMLLabelElement method getControl.

/**
 * @return the HTMLElement labeled by the given label object
 */
@JsxGetter({ CHROME, EDGE, FF, FF_ESR })
public HTMLElement getControl() {
    final HtmlLabel label = (HtmlLabel) getDomNodeOrDie();
    final HtmlElement labeledElement = label.getLabeledElement();
    if (labeledElement == null) {
        return null;
    }
    return (HTMLElement) getScriptableFor(labeledElement);
}
Also used : HtmlElement(com.gargoylesoftware.htmlunit.html.HtmlElement) HtmlLabel(com.gargoylesoftware.htmlunit.html.HtmlLabel) JsxGetter(com.gargoylesoftware.htmlunit.javascript.configuration.JsxGetter)

Example 2 with HtmlLabel

use of com.gargoylesoftware.htmlunit.html.HtmlLabel in project htmlunit by HtmlUnit.

the class HTMLLabelElement method getForm.

/**
 * Returns the value of the JavaScript {@code form} attribute.
 *
 * @return the value of the JavaScript {@code form} attribute
 */
@JsxGetter
@Override
public HTMLFormElement getForm() {
    if (getBrowserVersion().hasFeature(JS_LABEL_FORM_OF_SELF)) {
        final HtmlForm form = getDomNodeOrDie().getEnclosingForm();
        if (form == null) {
            return null;
        }
        return (HTMLFormElement) getScriptableFor(form);
    }
    final HtmlLabel label = (HtmlLabel) getDomNodeOrDie();
    final HtmlElement labeledElement = label.getLabeledElement();
    if (labeledElement == null) {
        return null;
    }
    final HtmlForm form = labeledElement.getEnclosingForm();
    if (form == null) {
        return null;
    }
    return (HTMLFormElement) getScriptableFor(form);
}
Also used : HtmlForm(com.gargoylesoftware.htmlunit.html.HtmlForm) HtmlElement(com.gargoylesoftware.htmlunit.html.HtmlElement) HtmlLabel(com.gargoylesoftware.htmlunit.html.HtmlLabel) JsxGetter(com.gargoylesoftware.htmlunit.javascript.configuration.JsxGetter)

Example 3 with HtmlLabel

use of com.gargoylesoftware.htmlunit.html.HtmlLabel in project htmlunit by HtmlUnit.

the class LabelsHelper method getElements.

/**
 * This is overridden instead of {@link #computeElements()} in order to prevent caching at all.
 *
 * {@inheritDoc}
 */
@Override
public List<DomNode> getElements() {
    final List<DomNode> response = new ArrayList<>();
    final DomElement domElement = (DomElement) getDomNodeOrDie();
    for (DomNode parent = domElement.getParentNode(); parent != null; parent = parent.getParentNode()) {
        if (parent instanceof HtmlLabel) {
            response.add(parent);
        }
    }
    final String id = domElement.getId();
    if (ATTRIBUTE_NOT_DEFINED != id) {
        for (final DomElement label : domElement.getHtmlPageOrNull().getElementsByTagName("label")) {
            if (id.equals(label.getAttributeDirect("for"))) {
                response.add(label);
            }
        }
    }
    return response;
}
Also used : DomNode(com.gargoylesoftware.htmlunit.html.DomNode) DomElement(com.gargoylesoftware.htmlunit.html.DomElement) ArrayList(java.util.ArrayList) HtmlLabel(com.gargoylesoftware.htmlunit.html.HtmlLabel)

Example 4 with HtmlLabel

use of com.gargoylesoftware.htmlunit.html.HtmlLabel in project security by jakartaee.

the class BaseHtmlUnitClient method getLabelIncludingFor.

// END validateAttributeSet
/*
   * In a given htmlpage(root) look for and return the child Label element from
   * the given parent element(tagName), That matches the givin String(forName)
   * to its "for" attribute.
   * 
   * Return null if no label element matches.
   */
protected HtmlLabel getLabelIncludingFor(HtmlPage root, String tagName, String forName) {
    HtmlLabel result = null;
    List list = root.getDocumentElement().getHtmlElementsByTagName(tagName);
    for (Iterator i = list.iterator(); i.hasNext(); ) {
        HtmlLabel label = (HtmlLabel) i.next();
        if (label.getForAttribute().indexOf(forName) > -1) {
            result = label;
        }
    }
    return result;
}
Also used : Iterator(java.util.Iterator) ArrayList(java.util.ArrayList) List(java.util.List) HtmlLabel(com.gargoylesoftware.htmlunit.html.HtmlLabel)

Example 5 with HtmlLabel

use of com.gargoylesoftware.htmlunit.html.HtmlLabel in project security by jakartaee.

the class BaseHtmlUnitClient method testList.

// End validateSelectOptions
/**
 * This test method is used for testing to List<String> objects.
 *
 * @param page
 *          - The HtmlPage that has the the test List Rendered.
 * @param myLabels
 *          - name of the HTMLLabel rendered.
 * @param expNum
 *          - The expected number
 * @param expValue
 *          - The List of expected Strings.
 * @param formatter
 *          - the Formatter that we want test output to be stored.
 * @param ordered
 *          - If true test the List object for ordering.
 */
protected void testList(HtmlPage page, String myLabels, List<String> expValue, int expSize, Formatter formatter, boolean ordered) {
    List<HtmlLabel> renderedList = getLabelsContaining(page, myLabels);
    String[] result;
    String rec;
    if (renderedList != null && !renderedList.isEmpty()) {
        int ii = renderedList.size();
        if (ii != expSize) {
            formatter.format("Unexpected Number of Items Rendered for " + myLabels + "! %n" + "Expected: %d %n" + "Received: %d %n", expSize, ii);
        }
    } else {
        formatter.format("No Labels found containing " + myLabels + "!");
    }
    if (ordered) {
        int i = 0;
        for (HtmlLabel label : renderedList) {
            result = label.asText().split(":");
            rec = result[1].trim();
            String expectedValue = expValue.get(i);
            if (!(expectedValue.equals(rec))) {
                formatter.format("Unexpected Value Rendered! %n" + "Found: %s %n" + "Expected: %s %n", rec, expectedValue);
            }
            i++;
        }
    } else {
        for (HtmlLabel label : renderedList) {
            result = label.asText().split(":");
            rec = result[1].trim();
            if (!(expValue.contains(rec))) {
                formatter.format("Unexpected Value Rendered! %n" + "Found: %s %n", rec);
            }
        }
    }
}
Also used : HtmlLabel(com.gargoylesoftware.htmlunit.html.HtmlLabel)

Aggregations

HtmlLabel (com.gargoylesoftware.htmlunit.html.HtmlLabel)19 ArrayList (java.util.ArrayList)9 HtmlPage (com.gargoylesoftware.htmlunit.html.HtmlPage)6 Formatter (java.util.Formatter)5 HtmlForm (com.gargoylesoftware.htmlunit.html.HtmlForm)4 HtmlElement (com.gargoylesoftware.htmlunit.html.HtmlElement)3 Test (org.junit.Test)3 DomNode (com.gargoylesoftware.htmlunit.html.DomNode)2 HtmlInput (com.gargoylesoftware.htmlunit.html.HtmlInput)2 HtmlTable (com.gargoylesoftware.htmlunit.html.HtmlTable)2 HtmlTableRow (com.gargoylesoftware.htmlunit.html.HtmlTableRow)2 JsxGetter (com.gargoylesoftware.htmlunit.javascript.configuration.JsxGetter)2 Iterator (java.util.Iterator)2 List (java.util.List)2 ScriptResult (com.gargoylesoftware.htmlunit.ScriptResult)1 DomElement (com.gargoylesoftware.htmlunit.html.DomElement)1 HtmlTextInput (com.gargoylesoftware.htmlunit.html.HtmlTextInput)1 Window (com.gargoylesoftware.htmlunit.javascript.host.Window)1 Document (com.gargoylesoftware.htmlunit.javascript.host.dom.Document)1 IOException (java.io.IOException)1