Vic Jang is right. You need to wrap the invocation in try-catch and rethrow the inner exception.
try {
return method.invoke(webElements, args);
} catch (InvocationTargetException ite) {
throw ite.getCause();
}
The reason is that "Method.invoke" wraps in InvocationTargetException those exceptions which are thrown in the method's code.
java.lang.reflect.Method:
Throws:
...
InvocationTargetException - if the underlying method throws an exception.
java.lang.reflect.InvocationTargetException:
InvocationTargetException is a checked exception that wraps an exception thrown by an invoked method or constructor.
The proxy object's class doesn't have InvocationTargetException declared among its "throws". That leads to UndeclaredThrowableException.