Skip to content

Commit

Permalink
#389 Support More Complex CSS Selectors
Browse files Browse the repository at this point in the history
Ensure attribute value is available.
  • Loading branch information
briemla committed Jan 18, 2020
1 parent acb2349 commit 0f9a639
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/main/java/de/retest/web/selenium/css/Has.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ private static Predicate<Element> hasAttribute( final String selector, final Pat

private static Predicate<Element> hasAttributeValue( final String attribute, final String attributeValue,
final BiPredicate<String, String> toPredicate ) {
return element -> toPredicate.test( element.getAttributeValue( attribute ).toString(), attributeValue );
return element -> null != element.getAttributeValue( attribute )
&& toPredicate.test( element.getAttributeValue( attribute ).toString(), attributeValue );
}

private static String clearQuotes( final String result ) {
Expand Down Expand Up @@ -94,6 +95,10 @@ public static Predicate<Element> cssClass( final String cssClass ) {
&& element.getIdentifyingAttributes().get( CLASS ).toString().contains( cssClass );
}

public static Predicate<Element> cssPseudoClass( final String cssPseudoClass ) {
return hasAttributeValue( "last-child", "true", String::equals );
}

public static Predicate<Element> cssName( final String name ) {
return element -> name.equals( element.getIdentifyingAttributes().get( NAME ) );
}
Expand Down

0 comments on commit 0f9a639

Please sign in to comment.