Permalink
Browse files

catch exception if node is not found

  • Loading branch information...
webfolderio committed Sep 3, 2018
1 parent 467a0a2 commit 147ced7a60c7e753414daac09265d39cf7dd87fa
Showing with 15 additions and 1 deletion.
  1. +15 −1 src/main/java/io/webfolder/cdp/session/Selector.java
@@ -27,6 +27,7 @@
import static java.lang.String.format;
import static java.lang.String.valueOf;
import static java.util.Collections.emptyList;
import static java.util.Locale.ENGLISH;

import java.util.ArrayList;
import java.util.List;
@@ -87,7 +88,20 @@ default boolean matches(
* selector
*/
default boolean matches(final Integer contextId, final String selector, final Object... args) {
Integer nodeId = getThis().getNodeId(contextId, selector, args);
Integer nodeId = null;
try {
nodeId = getThis().getNodeId(contextId, selector, args);
} catch (CdpException e) {
boolean notFound = e.getMessage() != null &&
e.getMessage()
.toLowerCase(ENGLISH)
.contains("could not find node with given id");
if (notFound) {
return false;
} else {
throw e;
}
}
if (nodeId == null || EMPTY_NODE_ID.equals(nodeId)) {
return false;
}

0 comments on commit 147ced7

Please sign in to comment.