gpt4 book ai didi

android - 定位除边界外具有相同属性值的 UI 对象

转载 作者:行者123 更新时间:2023-11-29 21:02:00 25 4
gpt4 key购买 nike

在自动化测试用例时,我遇到了这样的情况:多个对象在 UiAutomator 中显示相同的属性值,但边界除外(即显示器上的 x、y 位置)。我不想使用边界来定位对象。

在 AndroidViewClient 中,有一些方法可以找到特定对象及其属性。有什么方法可以在特定层次结构下定位对象。就像是:findViewByHierarchy(attr1:val1, attr2:val2, attr3:val3 ),其中 Id2 是 UI 树中 Id1 的子级,依此类推。如果没有,是否有任何解决方法可以实现相同的目的?

最佳答案

所有 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}
'''

此外,您可以自己遍历 View 树

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
'''

关于android - 定位除边界外具有相同属性值的 UI 对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25791426/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com