Poco icon indicating copy to clipboard operation
Poco copied to clipboard

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

Open letmeNo1 opened this issue 2 years ago • 1 comments
trafficstars

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

而元素列表如下: "12345.." 和 “connect” 全都在同一级,没有对应的关系 image

左侧的数字是随时变动的,我无法直接通过左侧数字定位到右侧的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]

letmeNo1 avatar May 19 '23 14:05 letmeNo1

已修改代码并提交了PR

letmeNo1 avatar May 21 '23 12:05 letmeNo1