Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
letmeNo1 opened this issue May 19, 2023 · 1 comment

Comments

@letmeNo1
Copy link

letmeNo1 commented May 19, 2023

现在我们有一个场景是
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
Copy link
Author

已修改代码并提交了PR

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant