Appium 请教各位大哥,在做 A 滑动的时候报错了一个问题

cherry09970 · March 19, 2025 · Last by 究客 replied at March 20, 2025 · 3003 hits

这个是 终端打印的
[7a9b49e9][W3C] Matched W3C error code 'unknown command' to UnknownCommandError
[7a9b49e9][HTTP] <-- POST /session/7a9b49e9-0471-4b9b-ba2a-5ee9b73c6e0f/touch/perform 404 22 ms - 3529
[5839e1c2][HTTP] --> GET /session/5839e1c2-233c-478f-bde2-f17ee89c1d0d/timeouts {}

这个是控制台打印的
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.WebDriverException: Message: The requested resource could not be found, or a request was received using an HTTP method that is not supported by the mapped resource

加了延迟好像也没有什么用
各位小哥哥小姐姐能说下具体是什么情况下
出来驾到 不太懂怎么发图片

共收到 3 条回复 时间 点赞

具体代码块发一下,滑动好好多方式,看你用的哪个?看报错是 http 不支持

究客 回复

老哥 我这边不太懂怎么贴图 新人嘛
然后这边确实 是报了 http 错误这类 用了 swipr scroll 都不太行 Touch 也不行
像这种 http 的 有什么办法可以解决嘛 老哥

试试下面的方法:
def swipe_up_count(count):
for _ in range(count): # 尝试滑动两次以确保成功
result = adb_swipe_up(
start_x_percent=0.5,
start_y_percent=0.8, # 调整起始点更靠近屏幕底部
end_x_percent=0.5,
end_y_percent=0.2, # 调整终点避免过度滑动
duration=500, # 增加滑动持续时间,使动作更平滑
)
if result:
print("滑动成功")
break
time.sleep(1)

def adb_swipe_up(
start_x_percent=0.5,
start_y_percent=0.7,
end_x_percent=0.5,
end_y_percent=0.3,
duration=300,
max_attempts=3,
delay=1,
):
"""使用 ADB 命令执行上滑操作,支持自定义滑动参数和重试机制

该函数提供以下功能:
1. 支持通过百分比设置滑动起始和终点位置
2. 自动获取设备屏幕尺寸并计算实际坐标
3. 可配置滑动持续时间
4. 内置重试机制,处理滑动失败的情况

Args:
start_x_percent (float): 起始点 x 坐标在屏幕宽度上的百分比,默认 0.5(屏幕中间)
start_y_percent (float): 起始点 y 坐标在屏幕高度上的百分比,默认 0.7(屏幕偏下位置)
end_x_percent (float): 终点 x 坐标在屏幕宽度上的百分比,默认 0.5(屏幕中间)
end_y_percent (float): 终点 y 坐标在屏幕高度上的百分比,默认 0.3(屏幕偏上位置)
duration (int): 滑动持续时间(毫秒),默认 300ms
max_attempts (int): 最大重试次数,默认 3 次
delay (int): 重试间隔时间,默认 1 秒

Returns:
bool: 滑动操作是否成功。成功返回 True,失败返回 False
"""
for attempt in range(max_attempts):
try:
# 获取屏幕尺寸
output = subprocess.check_output(["adb", "shell", "wm", "size"])
size_str = output.decode("utf-8").strip()
width, height = map(int, size_str.split(": ")[1].split("x"))

# 计算实际滑动坐标
start_x = int(width * start_x_percent)
start_y = int(height * start_y_percent)
end_x = int(width * end_x_percent)
end_y = int(height * end_y_percent)

print(
f"开始执行滑动操作:从 ({start_x}, {start_y}) 滑动到 ({end_x}, {end_y})"
)

# 执行滑动操作
try:
subprocess.run(
[
"adb",
"shell",
"input",
"swipe",
str(start_x),
str(start_y),
str(end_x),
str(end_y),
str(duration),
],
check=True,
)
time.sleep(0.5) # 等待滑动动画完成
print("滑动操作执行成功")
return True
except subprocess.CalledProcessError as swipe_error:
print(f"滑动操作执行失败: {swipe_error}")

except Exception as e:
print(f"第 {attempt + 1} 次滑动尝试失败: {e}")
time.sleep(delay)

return False

需要 Sign In 后方可回复, 如果你还没有账号请点击这里 Sign Up