这是自己写的部分代码:
from Bloom_test.device_config import *
from time import sleep
import re
import random
sources = driver.page_source
def get_page_source(resource):
sleep(3)
resource_id =
feedback = re.findall(‘resource-id=".*"’, resource)
for source in feedback:
if ‘resource-id’ and ‘clickable=“true”’ in source.split(’ ‘):
resource_id.append(source.split(’ ‘)[0].split(’/’)[1].split(’"’)[0])
# print(resource_id)
return list({}.fromkeys(resource_id).keys())
def get_page(end):
sleep(2)
sources = driver.page_source
resource_id = get_page_source(sources)
for i in range(end, len(resource_id)):
print(f"get page页点击的id:{resource_id[i]}")
try:
element = driver.find_element_by_id(resource_id[i])
search_enable = element.is_enabled()
if search_enable == True:
element.click()
sleep(2)
elements = driver.page_source
judge_page = get_page_source(elements)
print(judge_page)
if resource_id[i] not in judge_page and len(judge_page) != len(resource_id):
adb_back(1)
sleep(1)
else:
pass
except Exception as E:
print(E)
pass
def next_page_id():
sleep(3)
command = driver.page_source
next_id = get_page_source(command)
element =
for item in next_id:
if “iv_capture_home” not in item:
element.append(item)
return element
def compare_page(old_page, new_page):
if new_page == old_page:
return 1
else:
return 0
def click_action(id):
driver.implicitly_wait(5)
try:
driver.find_element_by_id(id).click()
except Exception as E:
print(E)
# get_id = next_page_id()
# print(f"get_id:{get_id}")
# for item in get_id:
# if “close” or “back” in item:
# print(item)
# driver.find_element_by_id(item).click()
def remove_duplicate_data(new_page, old_page):
clickable =
for item in new_page:
if item not in old_page:
clickable.append(item)
if len(clickable) == 0:
return 0, new_page
if len(clickable) <= len(new_page):
return 1, clickable
def new_idea(id_list, home):
click_action(id_list)
next_page = next_page_id()
print(f"第二层id列表:{next_page}")
if len(next_page) == 1:
click_action(next_page[0])
back_code = remove_duplicate_data(next_page, home)
if back_code == 0:
adb_back(1)
else:
for item in next_page:
print(f"要点击的id:{item}")
click_action(item)
sleep(1)
print("+++++++"*6)
new = next_page_id()
print(f"当前页面:{new}")
if compare_page(home, new) == 1:
click_action(id_list)
else:
if compare_page(home, new) == 0:
code, click_id = remove_duplicate_data(new, next_page)
print(f"可点击的id:{click_id}")
for element in click_id:
print(f"本次要点击的id:{element}")
click_action(element)
sleep(1)
next_new = next_page_id()
next_code, current_page = remove_duplicate_data(next_new, new)
if next_code == 0:
adb_back(1)
else:
page_num = random.randint(1, len(current_page)-1)
click_action(current_page[page_num])
else:
num = random.randint(1, len(home))
click_action(home[num])
sleep(1)
touchaction()
def run_current_page(page_id):
for element in page_id:
driver.implicitly_wait(3)
print(f"当前点击:{element}")
click_action(element)
sleep(2)
adb_back(1)
def single_page(single_id):
click_action(single_id)
new = next_page_id()
for item in new:
driver.implicitly_wait(3)
print(f"当前点击:{item}")
click_action(item)
sleep(2)
adb_back(1)
if name == ‘main’:
sources = driver.page_source
resource_id = get_page_source(sources)
print(resource_id)
run_current_page(resource_id)
print(f"next page click:{resource_id[-4]}")
single_page(resource_id[-4])
print(f"next page click:{resource_id[-3]}")
single_page(resource_id[-3])
print(f"next page click:{resource_id[-2]}")
single_page(resource_id[-2])
print(f"next page click:{resource_id[-1]}")
single_page(resource_id[-1])