python/appium实现模拟用户向下滑动查找应用商城app界面口碑最佳栏目的app,并将它输出

#确定屏幕尺寸
screen_size=driver.get_window_size()
s_heigt=screen_size['height']
s_width=screen_size['width']
start_x=s_width/2
start_y=s_width*0.8
end_x=start_x
end_y=start_y-300
#保存应用的标题
bestapptext=[]
#一边滑动一边找出口碑最佳目标元素
while True:
    #滑动操作
    driver.swipe(start_x,start_y,end_x,end_y)
    #目前的终止循环的条件是找到口碑元素
    koubei=driver.find_elements_by_xpath('//android.widget.TextView[@content-desc="best reputation"]')
# 思路发现要通过口碑最佳找到下面所有app名称text元素,了解到ImageView后面都跟着TextView。可以通过xpath找到
# //*[@content-desc="best reputation"]/following-sibling::android.widget.ImageView/following-sibling::android.widget.TextView[1]'
    if koubei:
        best_apps_kb=driver.find_elements_by_xpath(
            '//*[@content-desc="best reputation"]/following-sibling::android.widget.ImageView/following-sibling::android.widget.TextView[1]')
        bestapptext.extend([app.text for app in best_apps_kb])
        #如果发现用户最爱停止
    zuiai=driver.find_elements_by_xpath('//android.widget.TextView[@content-desc="user favorite"]')
    if zuiai:
        best_apps_za = driver.find_elements_by_xpath(
            '//*[@content-desc="best favorite"]/following-sibling::android.widget.ImageView/following-sibling::android.widget.TextView[1]')
        bestapptext.extend([app.text for app in best_apps_za])
        break
    #假设当前屏幕都是口碑最佳
    #if best_apps_kb==[] and best_apps_za==[]:
#打印结果
bestapptext=set(bestapptext)#相同的覆盖
print('口碑最佳得有:')
print(bestapptext)
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值