func (ele *Element) ScrollUp(step int) error {
	if err := ele.ua.post(
		&RPCOptions{
			Method: "scrollForward",
			Params: []interface{}{ele.selector, true, step},
		},
		nil,
		nil,
	); err != nil {
		return err
	}
	return nil
}
/*
Screen scroll up
package uiautomator
import (
	"encoding/json"
	"net/http"
	"time"
)
type (
	Selector map[string]interface{}
	Element struct {
		ua       *UIAutomator
		position *Position
		selector Selector
	}
	ElementRect struct {
		Bottom int `json:"bottom"`
		Left   int `json:"left"`
		Right  int `json:"right"`
		Top    int `json:"top"`
	}
	ElementInfo struct {
		ContentDescription string       `json:"contentDescription"`
		Checked            bool         `json:"checked"`
		Scrollable         bool         `json:"scrollable"`
		Text               string       `json:"text"`
		PackageName        string       `json:"packageName"`
		Selected           bool         `json:"selected"`
		Enabled            bool         `json:"enabled"`
		ClassName          string       `json:"className"`
		Focused            bool         `json:"focused"`
		Focusable          bool         `json:"focusable"`
		Clickable          bool         `json:"clickable"`
		ChileCount         int          `json:"chileCount"`
		LongClickable      bool         `json:"longClickable"`
		Checkable          bool         `json:"checkable"`
		Bounds             *ElementRect `json:"bounds"`
		VisibleBounds      *ElementRect `json:"visibleBounds"`
	}
)
var _MASK = map[string]int{
	"text":                  0x01,        
	"textContains":          0x02,        
	"textMatches":           0x04,        
	"textStartsWith":        0x08,        
	"className":             0x10,        
	"classNameMatches":      0x20,        
	"description":           0x40,        
	"descriptionContains":   0x80,        
	"descriptionMatches":    0x0100,      
	"descriptionStartsWith": 0x0200,      
	"checkable":             0x0400,      
	"checked":               0x0800,      
	"clickable":             0x1000,      
	"longClickable":         0x2000,      
	"scrollable":            0x4000,      
	"enabled":               0x8000,      
	"focusable":             0x010000,    
	"focused":               0x020000,    
	"selected":              0x040000,    
	"packageName":           0x080000,    
	"packageNameMatches":    0x100000,    
	"resourceId":            0x200000,    
	"resourceIdMatches":     0x400000,    
	"index":                 0x800000,    
	"instance":              0x01000000,  
}
func (ele Element) GetInfo() (*ElementInfo, error) {
	var RPCReturned ElementInfo
	if err := ele.ua.post(
		&RPCOptions{
			Method: "objInfo",
			Params: []interface{}{getParams(ele.selector)},
		},
		&RPCReturned,
		nil,
	); err != nil {
		return nil, err
	}
	return &RPCReturned, nil
}
func (ele Element) GetRect() (rect *ElementRect, err error) {
	info, err := ele.GetInfo()
	if err != nil {
		return
	}
	rect = info.Bounds
	if rect == nil {
		rect = info.VisibleBounds
	}
	return
}
func (ele Element) Center(offset *Position) (*Position, error) {
	rect, err := ele.GetRect()
	if err != nil {
		return nil, err
	}
	lx, ly, rx, ry := rect.Left, rect.Top, rect.Right, rect.Bottom
	width, height := rx-lx, ry-ly
	if offset == nil {
		offset = &Position{0.5, 0.5}
	}
	abs := &Position{}
	abs.X = float32(lx) + float32(width)*offset.X
	abs.Y = float32(ly) + float32(height)*offset.Y
	return abs, nil
}
func (ele Element) Count() (int, error) {
	var RPCReturned struct {
		Result int `json:"result"`
	}
	transform := func(response *http.Response) error {
		err := json.NewDecoder(response.Body).Decode(&RPCReturned)
		if err != nil {
			return err
		}
		return nil
	}
	return RPCReturned.Result, ele.ua.post(
		&RPCOptions{
			Method: "count",
			Params: []interface{}{getParams(ele.selector)},
		},
		nil,
		transform,
	)
}
func (ele Element) Clone() *Element {
	copied := ele
	copied.selector = make(Selector)
	for k, v := range ele.selector {
		copied.selector[k] = v
		if k == "childOrSiblingSelector" {
			nested := make([]interface{}, 0)
			for _, selector := range v.([]interface{}) {
				nested = append(nested, parseSelector(selector.(Selector)))
			}
			copied.selector[k] = nested
		}
	}
	return &copied
}
func (ele Element) Eq(index int) *Element {
	copied := ele.Clone()
	childOrSiblingSelector := copied.selector["childOrSiblingSelector"].([]interface{})
	lastSelectorIndex := len(childOrSiblingSelector)
	if lastSelectorIndex > 0 {
		lastSelector := childOrSiblingSelector[lastSelectorIndex-1].(Selector)
		lastSelector["instance"] = index
		newSelector := parseSelector(lastSelector)
		childOrSiblingSelector[lastSelectorIndex-1] = newSelector
	} else {
		copied.selector["instance"] = index
		newSelector := parseSelector(copied.selector)
		copied.selector = newSelector
	}
	return copied
}
func (ele Element) WaitForExists(duration float32, maxRetry int) error {
	if duration < 0 || duration > 60 {
		duration = WAIT_FOR_EXISTS_DURATION
	}
	if maxRetry < 0 || maxRetry > 10 {
		maxRetry = WAIT_FOR_EXISTS_MAX_RETRY
	}
	return ele.wait(duration, maxRetry, true)
}
func (ele Element) WaitUntilGone(duration float32, maxRetry int) error {
	if duration < 0 || duration > 60 {
		duration = WAIT_FOR_DISAPPEAR_DURATION
	}
	if maxRetry < 0 || maxRetry > 10 {
		maxRetry = WAIT_FOR_DISAPPEAR_MAX_RETRY
	}
	return ele.wait(duration, maxRetry, false)
}
func (ele Element) wait(duration float32, maxRetry int, exists bool) error {
	var (
		err    error
		retry  int
		method string
	)
	config := ele.ua.GetConfig()
	if exists {
		method = "waitForExists"
	} else {
		method = "waitUntilGone"
	}
	for {
		var RPCReturned struct {
			Result bool `json:"result"`
		}
		transform := func(response *http.Response) error {
			err := json.NewDecoder(response.Body).Decode(&RPCReturned)
			if err != nil {
				return err
			}
			return nil
		}
		err = ele.ua.post(
			&RPCOptions{
				Method: method,
				Params: []interface{}{getParams(ele.selector), config.Timeout * 1000},
			},
			nil,
			transform,
		)
		if err != nil || RPCReturned.Result == false {
			retry++
			if retry < maxRetry {
				time.Sleep(time.Duration(duration*1000) * time.Millisecond)
				continue
			}
			err = &UiaError{
				Code:    -32002,
				Message: "Element not found",
			}
			break
		}
		break
	}
	return err
}
func (ele Element) swipe(direction string) error {
	config := ele.ua.GetConfig()
	if err := ele.WaitForExists(config.WaitForExistsDuration, config.WaitForExistsMaxRetry); err != nil {
		return err
	}
	rect, err := ele.GetRect()
	if err != nil {
		return err
	}
	lx, ly, rx, ry := rect.Left, rect.Top, rect.Right, rect.Bottom
	cx, cy := (lx+rx)/2, (ly+ry)/2
	switch direction {
	case "up":
		return ele.ua.Swipe(
			&Position{X: float32(cx), Y: float32(cy)},
			&Position{X: float32(cx), Y: float32(ly)},
			20,
		)
	case "down":
		return ele.ua.Swipe(
			&Position{X: float32(cx), Y: float32(cy)},
			&Position{X: float32(cx), Y: float32(ry - 1)},
			20,
		)
	case "left":
		return ele.ua.Swipe(
			&Position{X: float32(cx), Y: float32(cy)},
			&Position{X: float32(lx), Y: float32(cy)},
			20,
		)
	case "right":
		return ele.ua.Swipe(
			&Position{X: float32(cx), Y: float32(cy)},
			&Position{X: float32(rx - 1), Y: float32(cy)},
			20,
		)
	}
	return nil
}
func (ele *Element) SwipeUp() error {
	return ele.swipe("up")
}
func (ele *Element) SwipeDown() error {
	return ele.swipe("down")
}
func (ele *Element) SwipeLeft() error {
	return ele.swipe("left")
}
func (ele *Element) SwipeRight() error {
	return ele.swipe("right")
}
func (ele *Element) Click(offset *Position) error {
	config := ele.ua.GetConfig()
	if err := ele.WaitForExists(config.WaitForExistsDuration, config.WaitForExistsMaxRetry); err != nil {
		return err
	}
	return ele.ClickNoWait(offset)
}
func (ele *Element) ClickNoWait(offset *Position) error {
	abs, err := ele.Center(offset)
	if err != nil {
		return err
	}
	return ele.ua.Click(abs)
}