from time import sleep from selenium.webdriver import ActionChains def tap_at_coordinate(driver, coord): # Primary (recommended) approach: modern Appium gesture API try: driver.execute_script("mobile: clickGesture", { "x": coord.x, "y": coord.y }) return except Exception: # Some devices / builds do not fully support clickGesture # Fall back to legacy coordinate tap pass # Fallback approach: older but sometimes more forgiving implementation driver.execute_script("mobile: tap", { "x": coord.x, "y": coord.y }) def scroll_page(driver, direction, small_scroll=False, times=None): y_coords = {'down': {'start': 1300, 'end': 470}, 'up': {'start': 470, 'end': 1300}} coords = y_coords.get(direction, {'start': None, 'end': None}) if small_scroll and direction == 'down': coords['start'] /= 3 coords['end'] /= 3 if small_scroll and direction == 'up': coords['end'] /= 2 if times is None: driver.swipe(5, coords['start'], 5, coords['end'], 400) else: for _ in range(times): driver.swipe(5, coords['start'], 5, coords['end'], 400) def slow_typing_with_actions(driver, element, text, delay=0.2): element.click() actions = ActionChains(driver) for char in text: actions.send_keys(char) actions.perform() sleep(delay) def press_enter(driver): driver.press_keycode(84) def hide_keyboard(driver): driver.hide_keyboard()