MCPcopy Index your code
hub / github.com/HtmlUnit/htmlunit / closest

Method closest

src/main/java/org/htmlunit/html/DomNode.java:2213–2240  ·  view source on GitHub ↗

@param selectorString the selector to test @return the selected DomElement or null.

(final String selectorString)

Source from the content-addressed store, hash-verified

2211 * @return the selected {@link DomElement} or null.
2212 */
2213 public DomElement closest(final String selectorString) {
2214 try {
2215 final WebClient webClient = getPage().getWebClient();
2216 final SelectorList selectorList = getSelectorList(selectorString, webClient);
2217
2218 DomNode current = this;
2219 if (selectorList != null) {
2220 do {
2221 for (final Selector selector : selectorList) {
2222 final DomElement elem = (DomElement) current;
2223 if (CssStyleSheet.selects(webClient.getBrowserVersion(), selector, elem, null, true, true)) {
2224 return elem;
2225 }
2226 }
2227
2228 do {
2229 current = current.getParentNode();
2230 }
2231 while (current != null && !(current instanceof DomElement));
2232 }
2233 while (current != null);
2234 }
2235 return null;
2236 }
2237 catch (final IOException e) {
2238 throw new CSSException("Error parsing CSS selectors from '" + selectorString + "': " + e.getMessage(), e);
2239 }
2240 }
2241
2242 /**
2243 * An unmodifiable empty {@link NamedNodeMap} implementation.

Callers 1

closestMethod · 0.95

Calls 7

getPageMethod · 0.95
getSelectorListMethod · 0.95
selectsMethod · 0.95
getBrowserVersionMethod · 0.95
getParentNodeMethod · 0.95
getMessageMethod · 0.80
getWebClientMethod · 0.65

Tested by

no test coverage detected