在小程序列表中长按删除总是报错

来源:1-1 课程目标及课程规划-导学

慕仰0001042

2019-11-26

http://img.mukewang.com/szimg/5ddd478a09a5b28d12470626.jpghttp://img.mukewang.com/szimg/5ddd481c082a98cf10802244.jpg


from appium import webdriver
import time
from appium.webdriver.common.touch_action import TouchAction
import unittest
import traceback

desired_caps = {
   'platformName':'Android',
   'platformVersion':'9',
   'deviceName':'21a9d094',
   'appPackage': 'com.tencent.mm',
   'appActivity': '.ui.LauncherUI',
   # 'unicodeKeyboard': True,
   # 'resetKeyboard': True,
   'noReset': True,
   'chromeOptions': {'androidProcess': 'com.tencent.mm:appbrand0'}
}

driver = webdriver.Remote('http://127.0.0.1:4723/wd/hub', desired_caps)
time.sleep(5)

def delete_mini_lefthand(driver):
   """
   从最近使用中删除左手医生小程序
   :param driver:
   :return:
   """
   l = driver.get_window_size()
   print(l['width'],l['height'])
   x1 = l['width'] * 0.5  # x坐标
   y1 = l['height'] * 0.25  # 起始y坐标
   y2 = l['height'] * 0.75  # 终点y坐标
   driver.swipe(x1, y1, x1, y2, 500)
   time.sleep(5)

   try:
       element = driver.find_element_by_xpath("//*[@text='左手医生']")
       TouchAction(driver).long_press(el=element,duration=2000).move_to(x = 468,y = 2029).release().perform()
       time.sleep(3)
   except Exception as e:
       traceback.print_exc()
       print(e,"找不到左手医生小程序")
   finally:
       driver.swipe(l['width']*0.5,l['height']*0.98, l['width']*0.5, l['height']*0.5,1000)
       print("返回到微信首页")

delete_mini_lefthand(driver)

http://img1.sycdn.imooc.com/szimg/5ddfeba80988b5a713660741.jpg

http://img.mukewang.com/szimg/5ddfec1e09c04c4012830614.jpg

写回答

3回答

Mushishi

2019-11-29

//img.mukewang.com/szimg/5de07bc809b37e3b10150508.jpg仔细看哟。然后先去找元素,看你找得到不。然后再去操作。

0
0

Mushishi

2019-11-29

看你的错误,不是长按,是你这个元素都没找到。

0
0

Mushishi

2019-11-28

//img.mukewang.com/szimg/5ddf2a910997626d06810220.jpg已经增加了try,你的错误抛出是多少行呢?那个上面的错误信息发一下

0
2
Mushishi
回复
慕仰0001042
看上面图片,元素不对
2019-11-29
共2条回复

Python主讲移动端自动化测试框架Appium

APP自动化基础知识、po模型、关键字模型、服务自动化、持续集成

1508 学习 · 1333 问题

查看课程