Python/appium simulates the user to slide down to find the app with the best public praise column in the app interface of the application mall, and outputs it
編輯:Python
# Determine screen size
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
# Save app title
bestapptext=[]
# Find the best target element of word of mouth while sliding
while True:
# Sliding operation
driver.swipe(start_x,start_y,end_x,end_y)
# The current condition for terminating the loop is to find the word-of-mouth element
koubei=driver.find_elements_by_xpath('//android.widget.TextView[@content-desc="best reputation"]')
# Train of thought to find all the following through word-of-mouth app name text Elements , come to know ImageView Followed by TextView. Can pass xpath find
# //*[@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])
# If you find that users love to stop
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
# Assume that the current screen has the best reputation
#if best_apps_kb==[] and best_apps_za==[]:
# Print the results
bestapptext=set(bestapptext)# The same coverage
print(' Word of mouth is the best :')
print(bestapptext)