Code example for JSONObject

Methods: has

0
  public ElementScrollNHandler(IOSServerManager driver, WebDriverLikeRequest request) {
    super(driver, request);
    String template = null;
 
    JSONObject payload = request.getPayload();
    if (payload.has("direction")) {
      String direction = payload.optString("direction");
      if (direction.equals("up")) {
        template = scrollUpTemplate;
      } else if (direction.equals("down")) {
        template = scrollDownTemplate;
      } else if (direction.equals("left")) {
        template = scrollLeftTemplate;
      } else if (direction.equals("right")) {
        template = scrollRightTemplate;
      } else { 
        throw new WebDriverException("Invalid value for scrolling direction"); 
      } 
 
    } else if (payload.has("name")) {
      String name = payload.optString("name");
      template = scrollToNameTemplate.replace(":name", name);
 
    } else if (payload.has("predicateString")) {
      String predicateString = payload.optString("predicateString");
      template = scrollToPredicateTemplate.replace(":predicateString", predicateString);
 
    } else if (payload.has("toVisible")) {
      template = scrollToVisibleTemplate;
 
    } else { 
      throw new WebDriverException("Unrecognised payload for ELEMENT_SCROLL");