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);
}
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);
}
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;
}
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;
}
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);
}
}
}
}
Aggregations