code: protected String buildEvalString(List<WebElement> elements, String script, Object... params) {
      String toSend;
  
      if (params != null && params.length > 0) {
        StringBuilder builder = new StringBuilder();
  
        for (Object object : params) {
          if (builder.toString().length() > 0) {
            builder.append(',');
          }
  
          if (object instanceof Collection<?>) {
            builder.append('[');
            Collection<?> collection = (Collection<?>) object;
  
            for (Object argument : collection) {
              processArgument(argument, builder, elements);
              builder.append(',');
            }
  
            int lastCharIndex = builder.length() - 1;
            if (builder.charAt(lastCharIndex) != '[') {
              builder.deleteCharAt(lastCharIndex);
            }
  
            builder.append(']');
          } else {
            processArgument(object, builder, elements);
          }
        }
  
        String arguments = builder.toString();
        toSend = String.format("(function(){%s})(%s)", script, arguments);
      } else {
        toSend = script;
      }
  
      return toSend;
    }
docs: Build the script to send with arguments.
  
  @param elements the web elements to send with the script as argument
  @param script   the script to execute, can have references to argument(s)
  @param params   params to send with the script, will be parsed in to arguments
  @return the script to be sent to Eval command for execution