Skip to content

Commit

Permalink
fix support for d(resourceId='android:id/text1')[-1].get_text()
Browse files Browse the repository at this point in the history
  • Loading branch information
codeskyblue committed Jun 10, 2020
1 parent e50bdc5 commit fddc5fa
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions uiautomator2/_selector.py
Original file line number Diff line number Diff line change
Expand Up @@ -407,7 +407,7 @@ def parent(self):
raise NotImplementedError()
# return UiObject(self.session, self.jsonrpc.getParent(self.selector))

def __getitem__(self, index):
def __getitem__(self, instance: int):
"""
Raises:
IndexError
Expand All @@ -417,7 +417,14 @@ def __getitem__(self, index):
"Index is not supported when UiObject returned by child_by_xxx"
)
selector = self.selector.clone()
selector.update_instance(index)
if instance < 0:
selector['instance'] = 0
del selector['instance']
count = self.jsonrpc.count(selector)
assert instance + count >= 0
instance += count

selector.update_instance(instance)
return UiObject(self.session, selector)

@property
Expand Down

0 comments on commit fddc5fa

Please sign in to comment.