use of org.openqa.selenium.SearchContext in project acceptance-test-harness by jenkinsci.
the class ByFactory method areaPath.
/**
* "/foo/bar" matches div elements with path attribute "/foo/bar" or "/foo/bar[n]". Does not match "/foo/bar/baz" or "/foo/bar[1]/baz".
*/
public By areaPath(final String pathPrefix) {
final int prefixLength = pathPrefix.length();
final By xpath = ByFactory.this.xpath("//div[starts-with(@path, '%s')]", pathPrefix);
return new By() {
@Override
public List<WebElement> findElements(SearchContext context) {
ArrayList<WebElement> ret = new ArrayList<>();
List<WebElement> allPrefixed = context.findElements(xpath);
for (WebElement webElement : allPrefixed) {
String path = webElement.getAttribute("path");
// Ensure /foo matches /foo and /boo[bar], but not /foo/bar or /foolish/bartender
if (path.substring(prefixLength).matches("^(\\[[^\\]]+\\]|)$")) {
ret.add(webElement);
}
}
return ret;
}
@Override
public String toString() {
return "By page area name: " + pathPrefix;
}
};
}
Aggregations