POCO學(xué)習(xí)筆記

Poco學(xué)習(xí)筆記

使用Poco選擇UI對象

基本選擇器

# 根據(jù)節(jié)點(diǎn)name選取
poco('bg_mission')

# 根據(jù)name和其他屬性
poco('bg_mission', type='Button')
poco(textMatches='^據(jù)點(diǎn).*$',type='Button',enable=True)

相對選擇器

通過UI之間的渲染層級關(guān)系進(jìn)行選擇,例如父子關(guān)系、祖先后代關(guān)系等。

# 通過父子關(guān)系/后代關(guān)系選擇
poco('main_node').child('list_item').offspring('item')

空間順序選擇器

poco(...)[1]

items = poco('main_node').child('list_item').offspring('item')
print(items[0].child('material_name').get_text())

迭代一組對象

items = poco('main_node').child('list_item').offspring('item')
for item in items:
    item.child('icn_item')

讀取屬性

mission_btn = poco('bg_mission')
print(mission_btn.attr('type'))  #獲取type屬性,'Button'
print(mission.btn.get_text()) #獲取元素內(nèi)文字
print(mission.btn.attr('text')) #同上
print(mission.btn.exists())  #返回True或False,該元素是否在屏幕上顯示

操作UI對象

點(diǎn)擊(click)

點(diǎn)擊默認(rèn)點(diǎn)在anchorPoint上,click()可以傳入一個參數(shù)[x,y],表示相對左上角的偏移量,左上角為[0,0],右下角為[1,1]

poco('bg_mission').click()
poco('bg_mission').click('center')
poco('bg_mission').click([0.5, 0.5]) #同上

滑動(swipe)

同樣以anchorPoint為起點(diǎn),然后朝給定向量方向滑動。

joystick = poco('movetouch_panel').child('point_img')
joystick.swipe('up')
joystick.swipe([0.2,-0.2]) #向右上角45度方向滑動
joystick.swipe([0.2,-0.2], duration=0.5)

拖拽(drag)

drag_to() 將一個UI拖到另一個UI。

poco(text='突破芯片').drag_to(poco(text='巖石司康餅'))

focus()drag_to()結(jié)合使用可產(chǎn)生卷動效果。

scrollView = poco(type='ScrollView')
scrollView.focus([0.5, 0.8]).drag_to(scrollView.focus([0.5, 0.2]))

等待出現(xiàn)(wait)

在給定時間內(nèi)等待一個UI出現(xiàn)并返回這個UI,如果已經(jīng)存在則直接返回這個UI。

poco('bg_mission').wait(5).click() #最多等待5秒鐘后點(diǎn)擊該UI
poco('bg_mission').wait(5).exists() #最多等待5秒鐘后返回值UI是否存在
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容