use of org.openqa.selenium.support.pagefactory.ElementLocator in project page-factory-2 by sbtqa.
the class CustomHtmlElementDecorator method decorateTypifiedElementList.
@Override
protected <T extends TypifiedElement> List<T> decorateTypifiedElementList(ClassLoader loader, Field field) {
final Class<T> elementClass = (Class<T>) HtmlElementUtils.getGenericParameterClass(field);
final ElementLocator locator = factory.createLocator(field);
final String name = getElementName(field);
InvocationHandler handler = new TypifiedElementListNamedProxyHandler(elementClass, locator, name) {
@Override
public Object invoke(Object o, Method method, Object[] objects) throws Throwable {
if ("toString".equals(method.getName())) {
return name;
}
List<T> elements = new LinkedList<>();
int elementNumber = 0;
for (WebElement element : locator.findElements()) {
String newName = String.format("%s [%d]", name, elementNumber++);
elements.add(createTypifiedElement(elementClass, element, newName));
}
try {
return method.invoke(elements, objects);
} catch (InvocationTargetException e) {
throw new AutotestError("Error initializing elements.", e);
}
}
};
return createTypifiedElementListProxy(loader, handler);
}
Aggregations