当前位置: 首页 > 工具软件 > Swipe > 使用案例 >

python+appium在使用swipe滑动时,报错The swipe did not complete successfully的解决办法

冯茂实
2023-12-01

在学习python+appium的滑动操作——swipe 时,运行的时候报错:
selenium.common.exceptions.WebDriverException: Message: An unknown server-side error occurred while processing the command. Original error: The swipe did not complete successfully

解决方法:只需在每次swipe之前,就使用强制等待1s即可,即添加一行 sleep(1) ,如下代码:

from time import sleep

from appium import webdriver
from selenium.webdriver.common.by import By

# 定义字典变量
desired_caps = {}
# 字典追加启动参数
desired_caps["platformName"] = "Android"
# 注意:版本号必须正确
desired_caps["platformVersion"] = "5.1.1"
# android不检测内容,但是不能为空
desired_caps["deviceName"] = "192.168.56.101:5555"
desired_caps["appPackage"] = "com.netease.newsreader.activity"
desired_caps["appActivity"] = "com.netease.nr.phone.main.MainActivity"
# 设置中⽂
desired_caps["unicodeKeyboard"] = True
desired_caps["resetKeyboard"] = True
# 获取driver
driver = webdriver.Remote("http://127.0.0.1:4723/wd/hub", desired_caps)

# 练习二:打开手机《网易新闻》应用,完成下面的步骤:
# ①.模拟手机滑动频道,找到‘健康’频道,并点击
# com.netease.newsreader.activity/com.netease.nr.phone.main.MainActivity
driver.implicitly_wait(10)
driver.find_element(By.ID,"com.netease.newsreader.activity:id/bkj").click()

i = 0
while i < 5:
    sleep(1) #每次swipe之前,强制等待1s
    driver.swipe(900, 200, 50, 200, duration=2000)
    i += 1
driver.find_element(By.XPATH,"//*[@text='健康']").click()

sleep(3)
driver.quit()

 类似资料: