Make shouldCache overridable/accessible
Added a getter method for shouldCache. So this is overridable and accessible in inheriting classes.
@@ -62,12 +62,12 @@ public DefaultElementLocator(SearchContext searchContext, AbstractAnnotations an
* Find the element.
*/
public WebElement findElement() {
- if (cachedElement != null && shouldCache) {
+ if (cachedElement != null && shouldCache()) {
return cachedElement;
}
WebElement element = searchContext.findElement(by);
- if (shouldCache) {
+ if (shouldCache()) {
cachedElement = element;
}
@@ -78,18 +78,27 @@ public WebElement findElement() {
* Find the element list.
*/
public List<WebElement> findElements() {
- if (cachedElementList != null && shouldCache) {
+ if (cachedElementList != null && shouldCache()) {
return cachedElementList;
}
List<WebElement> elements = searchContext.findElements(by);
- if (shouldCache) {
+ if (shouldCache()) {
cachedElementList = elements;
}
return elements;
}
+ /**
+ * Returns whether the element should be cached.
+ *
+ * @return {@code true} if the element should be cached
+ */
+ protected boolean shouldCache() {
+ return shouldCache;
+ }
+
@Override
public String toString() {
return this.getClass().getSimpleName() + " '" + by + "'";
