@param selectorString the selector to test @return the selected DomElement or null.
(final String selectorString)
| 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. |
no test coverage detected