2014-09-11 8 views
1

테스트 케이스를 자동화하는 동안 UiAutomator에서 여러 객체가 경계 (즉, 디스플레이의 x, y 위치)를 제외하고 동일한 속성 값을 표시하는 상황이 발생했습니다. 객체를 찾기 위해 범위를 사용하고 싶지 않습니다.경계를 제외하고 동일한 속성 값을 가진 UI 객체를 찾습니다

AndroidViewClient에는 속성이있는 특정 개체를 찾는 메소드가 있습니다. 특정 계층 구조에서 개체를 찾을 수있는 방법이 있습니까? 뭔가 : findViewByHierarchy(attr1:val1, attr2:val2, attr3:val3), 여기서 Id2는 UI 트리의 Id1의 하위 노드입니다. 그렇지 않은 경우 동일한 해결 방법을 사용할 수 있습니까?

+0

를 사용하여보기 트리를 직접 통과 할 수 당신이 찾고 계십니까? http://stackoverflow.com/questions/17680352/how-can-i-get-the-parent-of-a-view-using-uiautomator/17740212#17740212 –

답변

2

모든 findView*() 메서드는 검색을 수행하는 트리의 루트를 나타내는 root 매개 변수를받습니다. 예를 들어

: 또한

def findViewById(self, viewId, root="ROOT", viewFilter=None): 
    ''' 
    Finds the View with the specified viewId. 

    @type viewId: str 
    @param viewId: the ID of the view to find 
    @type root: str 
    @type root: View 
    @param root: the root node of the tree where the View will be searched 
    @type: viewFilter: function 
    @param viewFilter: a function that will be invoked providing the candidate View as a parameter 
         and depending on the return value (C{True} or C{False}) the View will be 
         selected and returned as the result of C{findViewById()} or ignored. 
         This can be C{None} and no extra filtering is applied. 

    @return: the C{View} found or C{None} 
    ''' 

, 당신은

def traverse(self, root="ROOT", indent="", transform=View.__str__, stream=sys.stdout): 
    ''' 
    Traverses the C{View} tree and prints its nodes. 

    The nodes are printed converting them to string but other transformations can be specified 
    by providing a method name as the C{transform} parameter. 

    @type root: L{View} 
    @param root: the root node from where the traverse starts 
    @type indent: str 
    @param indent: the indentation string to use to print the nodes 
    @type transform: method 
    @param transform: a method to use to transform the node before is printed 
    '''