日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問(wèn) 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) > 编程语言 > python >内容正文

python

Python笔记-U2控件操作和操作超时

發(fā)布時(shí)間:2025/3/15 python 18 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Python笔记-U2控件操作和操作超时 小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

以豌豆莢為例:

普通的操作:

import uiautomator2 as u2d = u2.connect_usb("8681-A01-0xc60fcc9d") d.app_start(package_name="com.wandoujia.phoenix2") print("step 1")# 通過(guò)多個(gè)條件來(lái)進(jìn)行限定 d(resourceId="android:id/text1", text="我的").click()print("step 2")

這里是可以的,但如果把“我的”改為“我的1”就會(huì)卡死:

通過(guò)timeout設(shè)置超時(shí):

import uiautomator2 as u2d = u2.connect_usb("8681-A01-0xc60fcc9d") d.app_start(package_name="com.wandoujia.phoenix2") print("step 1")# 通過(guò)多個(gè)條件來(lái)進(jìn)行限定 d(resourceId="android:id/text1", text="我的1").click(timeout=5)print("step 2")

這里可以看到UiObjectNotFoundError。

下面是使用click_exist

import uiautomator2 as u2d = u2.connect_usb("8681-A01-0xc60fcc9d") d.app_start(package_name="com.wandoujia.phoenix2") print("step 1")# 通過(guò)多個(gè)條件來(lái)進(jìn)行限定 #d(resourceId="android:id/text1", text="我的1").click(timeout=5)#clicke_exists如果控件存在就點(diǎn)擊,不存在就返回 d(resourceId="android:id/text1", text="我的1").click_exists(timeout=5)print("step 2")

下面是通過(guò)exists屬性判斷控件是否存在:

import uiautomator2 as u2d = u2.connect_usb("8681-A01-0xc60fcc9d") d.app_start(package_name="com.wandoujia.phoenix2") print("step 1")# 通過(guò)多個(gè)條件來(lái)進(jìn)行限定 #d(resourceId="android:id/text1", text="我的1").click(timeout=5)#clicke_exists如果控件存在就點(diǎn)擊,不存在就返回 #d(resourceId="android:id/text1", text="我的1").click_exists(timeout=5)#在操作之前,通過(guò)exists屬性判斷控件是否存在 print(d(resourceId="android:id/text1", text="我的1").exists(timeout=5))print("step 2")

下面是獲取控件信息:

這里用python獲取最下面的android.widget.LinearLayout

import uiautomator2 as u2d = u2.connect_usb("8681-A01-0xc60fcc9d") d.app_start(package_name="com.wandoujia.phoenix2") print("step 1")# 通過(guò)多個(gè)條件來(lái)進(jìn)行限定 #d(resourceId="android:id/text1", text="我的1").click(timeout=5)#clicke_exists如果控件存在就點(diǎn)擊,不存在就返回 #d(resourceId="android:id/text1", text="我的1").click_exists(timeout=5)#在操作之前,通過(guò)exists屬性判斷控件是否存在 #print(d(resourceId="android:id/text1", text="我的1").exists(timeout=5))print(d(resourceId="com.wandoujia.phoenix2:id/a_4").child(className="android.widget.LinearLayout").child(resourceId="com.wandoujia.phoenix2:id/g8").count)for view in d(resourceId="com.wandoujia.phoenix2:id/a_4").child(className="android.widget.LinearLayout").child(resourceId="com.wandoujia.phoenix2:id/g8"):print(view.info)print("step 2")

運(yùn)行截圖如下:

總結(jié)

以上是生活随笔為你收集整理的Python笔记-U2控件操作和操作超时的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。

如果覺(jué)得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。