小练习~忽略

2019-07-07  本文已影响0人  自如_

应用市场查看口碑最佳应用:

我们打开 apk 发现它有一个排行榜

image.png

要求是屏幕向上滚动,它有一个口碑最佳的排行榜


image.png

让我们把口碑最佳几个 app 的名称全都打印下来。

# coding=utf8
import time

from appium import webdriver


desired_caps = {
    'platformName': 'Android',
    'platformVersion': '6',
    'deviceName': 'glaxy5',
    # 'app': r'd:\apk\sqatuo.apk',
    'appPackage': 'com.sqauto',
    'appActivity': 'com.sqauto.MainActivity',
    'noReset': True,
    'newCommandTimeout': 6000,
}

driver = webdriver.Remote('http://localhost:4723/wd/hub', desired_caps) #启动Remote RPC
driver.implicitly_wait(10)


#发现最佳口碑后拖动终点--松勤推荐
target = driver.find_element_by_accessibility_id('songqin recommend')
targetY=target.location['y']

#确定每次移动的距离
app_img=driver.find_element_by_xpath('//android.widget.TextView[@content-desc="songqin recommend"]/following-sibling::android.widget.ImageView')
move_distance=app_img.size['height']

#确定拖动起点
ele=driver.find_element_by_accessibility_id('cramp fast')
xPos=ele.location['x']+ele.size['width']/2
yPos=ele.location['y']+ele.size['height']/2

driver.implicitly_wait(0.5)
while True:
    driver.swipe(xPos,yPos,xPos,yPos-move_distance,500)

    kb_ele=driver.find_elements_by_accessibility_id('best reputation')
    if kb_ele:
        #找到口碑最佳了
        break

driver.implicitly_wait(10)

#直接将口碑滑动到松勤推荐的位置
#start_y=kb_ele[0].location['y']+ele.size['height']/2 #口碑最佳中心点y坐标

driver.swipe(xPos, kb_ele[0].location['y'], xPos,targetY,3000)

xpath='//android.widget.TextView[@content-desc="best reputation"]/following-sibling::android.widget.ImageView/following-sibling::android.widget.TextView[1]'

app_eles=driver.find_elements_by_xpath(xpath)
print('口碑最佳应用有:')

[print(ele.text) for ele in app_eles]



input('**** Press to quit..')
driver.quit()
上一篇下一篇

猜你喜欢

热点阅读