String reference = request.getVariableValue(":reference");
String sessionId = request.getSession();
final String js;
JSONObject payload = request.getPayload();
if (payload.has("direction")) {
JSTemplate template;
switch (payload.optString("direction")) {
case "up": template = scrollUpTemplate; break;
case "down": template = scrollDownTemplate; break;
case "left": template = scrollLeftTemplate; break;
case "right": template = scrollRightTemplate; break;
default: throw new WebDriverException("Invalid value for scrolling direction");
}
js = template.generate(sessionId, reference);
} else if (payload.has("name")) {
String name = payload.optString("name");
js = scrollToNameTemplate.generate(sessionId, reference, name);
} else if (payload.has("predicateString")) {
String predicateString = payload.optString("predicateString");