目的:全面K歌,一個(gè)作者作品的頁(yè)面,獲取到第二個(gè)“A B C D E F G”并點(diǎn)擊進(jìn)入。
第一種方法:
代碼:
# -*- encoding=utf8 -*-
__author__ = "jiangjiahao"
from airtest.core.api import *
from poco.drivers.android.uiautomation import AndroidUiautomationPoco
poco = AndroidUiautomationPoco(use_airtest_input=True, screenshot_each_action=False)
auto_setup(__file__)
# 獲取第二個(gè)“A B C D E F G”
# 核心思想,i j 獲取到對(duì)應(yīng)的目標(biāo)值
i = 0
j = 0
k = 0
for i in range(3):
? ? for j in range(3):
? ? ? ? #每個(gè)標(biāo)題都是以這個(gè)開(kāi)頭
? ? ? ? text_targer = poco("android.widget.LinearLayout").offspring("android:id/content").offspring(
? ? ? ? ? ? "com.tencent.karaoke:id/b9c").child("com.tencent.karaoke:id/bya")[i].child(
? ? ? ? ? ? "android.widget.LinearLayout")[j].offspring("com.tencent.karaoke:id/by8").get_text()
? ? ? ? if str(text_targer.strip()) == "A B C D E F G":
? ? ? ? ? ? k += 1
? ? ? ? ? ? if k == 2:? #得到第二個(gè)判斷
? ? ? ? ? ? ? ? #每個(gè)視頻進(jìn)入的入口都是以這個(gè)開(kāi)頭
? ? ? ? ? ? ? ? poco("android.widget.LinearLayout").offspring("com.tencent.karaoke:id/b9c").child(
? ? ? ? ? ? ? ? ? ? "com.tencent.karaoke:id/bya")[i].child("android.widget.LinearLayout")[j].offspring(
? ? ? ? ? ? ? ? ? ? "com.tencent.karaoke:id/by4").click()
如果批量全部判斷:
代碼:
# -*- encoding=utf8 -*-
__author__ = "jiangjiahao"
from airtest.core.api import *
from poco.drivers.android.uiautomation import AndroidUiautomationPoco
poco = AndroidUiautomationPoco(use_airtest_input=True, screenshot_each_action=False)
auto_setup(__file__)
num = int(poco("com.tencent.karaoke:id/j_6").get_text())
print(num)
max_j = int(num%3)
max_i = int((num-max_j)/3)
# 獲取第二個(gè)“A B C D E F G”
# 核心思想,i j 獲取到對(duì)應(yīng)的目標(biāo)值
i = 0
j = 0
k = 0
for i in range(max_i+1):
? ? if i != max_i:
? ? ? ? for j in range(3):
? ? ? ? #每個(gè)標(biāo)題都是以這個(gè)開(kāi)頭
? ? ? ? ? ? text_targer = poco("android.widget.LinearLayout").offspring("android:id/content").offspring(
? ? ? ? ? ? ? ? "com.tencent.karaoke:id/b9c").child("com.tencent.karaoke:id/bya")[i].child(
? ? ? ? ? ? ? ? "android.widget.LinearLayout")[j].offspring("com.tencent.karaoke:id/by8").get_text()
? ? ? ? ? ? if str(text_targer.strip()) == "A B C D E F G":
? ? ? ? ? ? ? ? k += 1
? ? ? ? ? ? ? ? if k == 2:? #得到第二個(gè)判斷
? ? ? ? ? ? ? ? ? ? #每個(gè)視頻進(jìn)入的入口都是以這個(gè)開(kāi)頭
? ? ? ? ? ? ? ? ? ? poco("android.widget.LinearLayout").offspring("com.tencent.karaoke:id/b9c").child(
? ? ? ? ? ? ? ? ? ? ? ? "com.tencent.karaoke:id/bya")[i].child("android.widget.LinearLayout")[j].offspring(
? ? ? ? ? ? ? ? ? ? ? ? "com.tencent.karaoke:id/by4").click()
? ? else:
? ? ? ? for j in range(max_j+1):
? ? ? ? #每個(gè)標(biāo)題都是以這個(gè)開(kāi)頭
? ? ? ? ? ? text_targer = poco("android.widget.LinearLayout").offspring("android:id/content").offspring(
? ? ? ? ? ? ? ? "com.tencent.karaoke:id/b9c").child("com.tencent.karaoke:id/bya")[i].child(
? ? ? ? ? ? ? ? "android.widget.LinearLayout")[j].offspring("com.tencent.karaoke:id/by8").get_text()
? ? ? ? ? ? if str(text_targer.strip()) == "A B C D E F G":
? ? ? ? ? ? ? ? k += 1
? ? ? ? ? ? ? ? if k == 2:? #得到第二個(gè)判斷
? ? ? ? ? ? ? ? ? ? #每個(gè)視頻進(jìn)入的入口都是以這個(gè)開(kāi)頭
? ? ? ? ? ? ? ? ? ? poco("android.widget.LinearLayout").offspring("com.tencent.karaoke:id/b9c").child(
? ? ? ? ? ? ? ? ? ? ? ? "com.tencent.karaoke:id/bya")[i].child("android.widget.LinearLayout")[j].offspring(
? ? ? ? ? ? ? ? ? ? ? ? "com.tencent.karaoke:id/by4").click()
后面還需要,滑動(dòng)swipe.
完成!
第二種辦法:
后面更新.....................