#确定屏幕尺寸
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)
python/appium实现模拟用户向下滑动查找应用商城app界面口碑最佳栏目的app,并将它输出
最新推荐文章于 2022-06-01 21:34:29 发布