Constand for background color added as well as a helper method to create

a XPath predicate which checks for style classes
This commit is contained in:
D049941 committed 2014-03-21 18:20:26 +01:00
1 parent c3483ae501
commit cfed83ca10
2 files changed
+26 -1

No files matched your search

@@ -7,4 +7,6 @@ public interface CSSConstants {
public static final String CSS_STYLE_ATTRIBUTE_NAME = "style"; //$NON-NLS-1$
public static final String CSS_BACKGROUND_IMAGE = "background-image"; //$NON-NLS-1$
public static final String CSS_BACKGROUND_COLOR = "background-color"; //$NON-NLS-1$
}
@@ -6,7 +6,30 @@ import java.util.List;
import org.openqa.selenium.WebElement;
public class CSSHelper {
public class CSSHelper {
/**
* <p>Creates an XPath 1.0 predicate that matches if an element has the given style sheet class in its "class"
* attribute.</p>
*
* @param className
* The name of the style sheet class to check for.
* @return
* An XPath predicate that matches if an element has the given style sheet class in its "class" attribute.
*/
public static String containsCSSClassPredicate(String className) {
return "contains(concat(' ',normalize-space(@class),' '),' " + className + " ')";
}
public static String containsCSSClassesPredicate(String... classNames) {
StringBuilder builder = new StringBuilder(70 * classNames.length);
for(String className : classNames) {
builder.append(containsCSSClassPredicate(className));
builder.append(" and ");
}
return builder.substring(0, builder.length() - 5);
}
public static List<String> getCSSClassNames(WebElement element) {
String cssClasses = element.getAttribute(CSSConstants.CSS_CLASS_ATTRIBUTE_NAME);