Appium对android.view.View进行操作

终于开始用appium写东西了,结果碰上了一个上下滑动选择的地方,用uiautomatorviewer查看发现,这居然是一整个元素,网上搜了搜它的class,找到了这样一篇代码,先存起来,继续写的时候用

原贴网址:https://www.cnblogs.com/cherry-ning/articles/11178237.html

from appium import webdriver
import time

desired_caps = {}
desired_caps['platformName'] = 'Android'
desired_caps['platformVersion'] = '8.0.0'
desired_caps['deviceName'] = 'XXX'


driver = webdriver.Remote('http://localhost:4723/wd/hub', desired_caps)
#通过resoure-id知道view
ele=driver.find_element_by_id('com.mymoney:id/first_level_wv')
#获取到view的宽和高----w=360-0=360 ; h=1280-977=303
w=ele.size['width']
h=ele.size['height']
print(w,h)
#获取到view的起始纵坐标----977,其实横坐标为0
y=ele.location['y']
x1=int(w/2)
y1=int(h/5*4+y)
y2=int(h/5*3+y)
print(x1,y1,y2)
#连续滑动三次
for i in range(3):
    driver.swipe(x1,y1,x1,y2,1000)
    time.sleep(1)

你可能感兴趣的:(appium)