Touches the center of this C{View}. The touch can be displaced from the center by using C{deltaX} and C{deltaY} values. @param eventType: The event type @type eventType: L{adbclient.DOWN}, L{adbclient.UP} or L{adbclient.DOWN_AND_UP} @param deltaX: Displaceme
(self, eventType=adbclient.DOWN_AND_UP, deltaX=0, deltaY=0)
| 979 | return 0, 0 |
| 980 | |
| 981 | def touch(self, eventType=adbclient.DOWN_AND_UP, deltaX=0, deltaY=0): |
| 982 | """ |
| 983 | Touches the center of this C{View}. The touch can be displaced from the center by |
| 984 | using C{deltaX} and C{deltaY} values. |
| 985 | |
| 986 | @param eventType: The event type |
| 987 | @type eventType: L{adbclient.DOWN}, L{adbclient.UP} or L{adbclient.DOWN_AND_UP} |
| 988 | @param deltaX: Displacement from center (X axis) |
| 989 | @type deltaX: int |
| 990 | @param deltaY: Displacement from center (Y axis) |
| 991 | @type deltaY: int |
| 992 | """ |
| 993 | |
| 994 | x, y = self.getCenter() |
| 995 | if deltaX: |
| 996 | x += deltaX |
| 997 | if deltaY: |
| 998 | y += deltaY |
| 999 | if DEBUG_TOUCH: |
| 1000 | print("should touch @ (%d, %d)" % (x, y), file=sys.stderr) |
| 1001 | if VIEW_CLIENT_TOUCH_WORKAROUND_ENABLED and eventType == adbclient.DOWN_AND_UP: |
| 1002 | if WARNINGS: |
| 1003 | print("ViewClient: touch workaround enabled", file=sys.stderr) |
| 1004 | self.device.touch(x, y, eventType=adbclient.DOWN) |
| 1005 | time.sleep(50 / 1000.0) |
| 1006 | self.device.touch(x + 10, y + 10, eventType=adbclient.UP) |
| 1007 | else: |
| 1008 | if self.uiAutomatorHelper: |
| 1009 | selector = self.obtain_selector() |
| 1010 | if DEBUG_UI_AUTOMATOR_HELPER: |
| 1011 | print('using selector="%s"' % selector, file=sys.stderr) |
| 1012 | if selector: |
| 1013 | try: |
| 1014 | object_ref = self.uiAutomatorHelper.ui_device.find_object(body=selector) |
| 1015 | if DEBUG_UI_AUTOMATOR_HELPER: |
| 1016 | print("oid=%d" % object_ref.oid, file=sys.stderr) |
| 1017 | self.uiAutomatorHelper.ui_object2.click(oid=object_ref.oid) |
| 1018 | except RuntimeError as e: |
| 1019 | print(e, file=sys.stderr) |
| 1020 | print("UiObject2 click failed, falling back to coordinates", file=sys.stderr) |
| 1021 | self.uiAutomatorHelper.ui_device.click(x=x, y=y) |
| 1022 | else: |
| 1023 | # FIXME: |
| 1024 | # The View has no CD, TEXT or ID so we cannot use it in a selector to findObject() |
| 1025 | # We should try content description, text, and perhaps other properties before surrendering. |
| 1026 | # For now, tet's fall back to click(x, y) |
| 1027 | self.uiAutomatorHelper.ui_device.click(x=x, y=y) |
| 1028 | else: |
| 1029 | self.device.touch(x, y, eventType=eventType) |
| 1030 | |
| 1031 | def escapeSelectorChars(self, selector): |
| 1032 | return selector.replace('@', '\\@').replace(',', '\\,') |