-
Notifications
You must be signed in to change notification settings - Fork 438
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
WIP: Add tapping of accessibility element using AXLabel #758
base: main
Are you sure you want to change the base?
Changes from all commits
24c1cff
6cb90e2
b52faee
329d6e1
51faba8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,6 +8,7 @@ | |
import functools | ||
import inspect | ||
import logging | ||
import json | ||
import os | ||
import shutil | ||
import sys | ||
|
@@ -65,6 +66,7 @@ | |
FileEntryInfo, | ||
FileListing, | ||
HIDButtonType, | ||
HIDElementType, | ||
HIDEvent, | ||
IdbConnectionException, | ||
IdbException, | ||
|
@@ -789,6 +791,48 @@ async def list_xctests(self) -> List[InstalledTestInfo]: | |
async def send_events(self, events: Iterable[HIDEvent]) -> None: | ||
await self.hid(iterator_to_async_iterator(events)) | ||
|
||
@log_and_handle_exceptions | ||
async def axtap( | ||
self, | ||
element: HIDElementType, | ||
label: str, | ||
x: float, | ||
y: float, | ||
duration: Optional[float] = None, | ||
count: Optional[int] = 1, | ||
) -> None: | ||
accessibilityInfo = await self.stub.accessibility_info( | ||
AccessibilityInfoRequest( | ||
point=None, | ||
format=(AccessibilityInfoRequest.LEGACY), | ||
) | ||
) | ||
|
||
elementFound = False | ||
|
||
for item in json.loads(accessibilityInfo.json): | ||
try: | ||
axElement = HIDElementType(item["role_description"]) | ||
axLabel = item["AXLabel"] | ||
|
||
elementFound = axElement == element and ( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For all the element types except for The current behavior is that:
Succeeds and returns the first There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, it just uses the first element of the type. It's debatable where or not that is useful because I don't know if we can guarantee that the order of |
||
label is None or axLabel == label | ||
) | ||
|
||
if elementFound: | ||
axframe = item["frame"] | ||
x += axframe["x"] | ||
y += axframe["y"] | ||
break | ||
except: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What could make it There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think the enum will I'm happy to change that if there is a preferred way of handling this scenario. |
||
pass | ||
|
||
if elementFound: | ||
for n in range(count): | ||
await self.send_events(tap_to_events(x, y, duration)) | ||
else: | ||
print("AXElement with AXLabel: ", label, " type: ", element, " not found.") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We could log it, however let's not send it to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 Can change to logging instead of print. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would not preserve the current |
||
|
||
@log_and_handle_exceptions | ||
async def tap(self, x: float, y: float, duration: Optional[float] = None) -> None: | ||
await self.send_events(tap_to_events(x, y, duration)) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you show an example of each of these from an actual output?