AirtestProject / AirtestProject/Poco

能否新增一个获取某个元素在其兄弟节点中的索引值,或者可以直接获取该元素的上一个节点和下一个节点

未关闭
#585 1 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看
主要语言
Python
星标
2k
派生
341
PR 合并指标
30 天内没有已合并 PR

描述

现在我们有一个场景是
1234567 | connect
1234568 | connect
1234569 | connect
1234566 | connect

而元素列表如下: "12345.." 和 “connect” 全都在同一级,没有对应的关系
![image](https://github.com/AirtestProject/Poco/assets/44250052/921fda59-588f-40b1-90dd-3fed7be7b580)

左侧的数字是随时变动的,我无法直接通过左侧数字定位到右侧的connect 的按钮

我自己写了一个解决的方案,但是速度不尽如人意,想来应该还是得从更底层去解决这个
def index(self):
"""
Returns the index of the element in the subset of the parent element

"""
start = time.time()
sub_query = build_query(None) # as placeholder
query = ('-', (self.query, sub_query))
obj = UIObjectProxy(self.poco)
obj.query = query
position = [x.get_position() for x in obj]
return position.index(self.get_position())

def last_sibling(self):
"""
Returns the sibling to the left of an element

"""
sub_query = build_query(None)
query = ('-', (self.query, sub_query))
obj = UIObjectProxy(self.poco)
obj.query = query
return obj[self.index() - 1]

def next_sibling(self):
"""
Returns the sibling to the right of an element

"""
sub_query = build_query(None)
query = ('-', (self.query, sub_query))
obj = UIObjectProxy(self.poco)
obj.query = query
return obj[self.index()+1]

贡献指南

这个仓库没有索引到贡献指南

评估

这个 Issue 还没有评估数据。

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。