def get_element_rect(self, xpath: str, wait_time: float = 5, interval_time: float = 0.5) -》 tuple:
"""
获取元素位置
Gets the position of the element and returns the coordinates of the upper left corner and the lower right corner of the element area
xpath: xpath 路径
wait_time: 找不到元素等待时间,默认 5秒
interval_time: 找不到元素循环查找间隔时间,默认 0.5秒
return: x,y坐标 或者 空()
xpath: xpath path
wait_time: waiting time, which is 5 seconds by default
interval_time: the polling interval, which is 0.5 seconds by default
return: x,y coordinates or empty ()
"""
# 使用示例 [Demo]
result = self.get_element_rect("elemns/g[0]", 5, 0.5)
print(result)
def press_release_by_ele(self, xpath, duration: float, wait_time: float = 5, interval_time: float = 0.5) -》 bool:
"""
按压元素并释放
Press the element and release
xpath: 要按压的元素
duration: 按压时长,单位秒
wait_time: 找不到元素等待时间,默认 5秒
interval_time: 找不到元素循环查找间隔时间,默认 0.5秒
return: Ture 或者 False
xpath: the element to press
duration: duration of pressing, in seconds
wait_time: The longest waiting time for finding an element defaults to 5 seconds
interval_time: The polling interval of the lookup element defaults to 0.5
return: Ture or False
"""
# 使用示例 [Demo]
result = self.press_release_by_ele("button/[0]", 2, 5, 0.5)
print(result)
def get_element_desc(self, xpath: str, wait_time: float = 5, interval_time: float = 0.5) -》 str:
"""
获取元素描述
Get element description
xpath: xpath 路径
wait_time: 找不到元素等待时间,默认 5秒
interval_time: 找不到元素循环查找间隔时间,默认 0.5秒
return: 元素描述字符串
xpath: xpath path
wait_time: the waiting time, which is self.wait_timeout by default to 5 seconds
interval_time: polling interval; self.interval_timeout is selected by default to 0.5
return: element description string
"""
# 使用示例 [Demo]
result = self.get_element_desc("button/[0]", 5, 0.5)
print(result)
def get_element_text(self, xpath: str, wait_time: float = 5, interval_time: float = 0.5) -》 str:
"""
获取文本 [和上面获取元素描述差不多, 获取文本对文本输入框有效]
Get element text
xpath: xpath 路径
wait_time: 找不到元素等待时间,默认 5秒
interval_time: 找不到元素循环查找间隔时间,默认 0.5秒
return: 元素文本
xpath: xpath path
wait_time: waiting time, which is 5 seconds by default.
interval_time: the polling interval, which is 0.5 seconds by default.
return: element text
"""
# 使用示例 [Demo]
result = self.get_element_text("button/[1]", 5, 0.5)
print(result)
def set_element_text(self, xpath: str, text: str, wait_time: float = 5, interval_time: float = 0.5) -》 bool:
"""
设置元素文本
Set element text
xpath: 元素路径
text: 设置的文本
wait_time: 找不到元素等待时间,默认 5秒
interval_time: 找不到元素循环查找间隔时间,默认 0.5秒
return: 成功返回True 失败返回False
xpath: element path
text: the text of the setting
wait_time: the waiting time, which is self.wait_timeout by default
interval_time: polling interval; self.interval_timeout is selected by default
return: Returns True successfully, and returns False if it fails
"""
# 使用示例 [Demo]
result = self.set_element_text("button/[5]", "I am PyAibote", 5, 0.5)
print(result)
def click_element(self, xpath: str, wait_time: float = 5, interval_time: float = 0.5) -》 bool:
"""
点击元素
Click element
xpath: 元素路径
wait_time: 找不到元素等待时间,默认 5秒
interval_time: 找不到元素循环查找间隔时间,默认 0.5秒
return: 成功返回True 失败返回False
xpath: element path
wait_time: waiting time, which is 5 seconds by default
interval_time: the polling interval, which is 0.5 seconds by default
return: Returns True successfully, and returns False if it fails
"""
# 使用示例 [Demo]
result = self.click_element("button/[8]", 5, 0.5)
print(result)
result = self.click_element("android.widget.TextView@containsText=ibote", 5, 0.5) #文本模糊匹配点击元素
print(result)
result = self.click_element("android.widget.TextView@containsDesc=ibote", 5, 0.5) #描述模糊匹配点击元素
print(result)
result = self.click_element("android.widget.TextView@containsDesc[1]=ibote", 5, 0.5) #描述模糊匹配点击第二个匹配到的元素
print(result)
注意: 安卓所有元素功能xpath都支持@containsText 和 @containsDesc 模糊定位,使用示例同上
def click_any_elements(self, xpath_list: list, wait_time: float = 5, interval_time: float = 0.5) -》 bool:
"""
遍历点击列表中的元素
Traverse the elements in the click list until any element returns True
xpath_list: xpath 列表
wait_time: 找不到元素等待时间,默认 5秒
interval_time: 找不到元素循环查找间隔时间,默认 0.5秒
return: 直到任意一个元素被点击返回 True, 失败返回False
xpath_list: xpath list
wait_time: waiting time, which is 5 seconds by default
interval_time: the polling interval, which is 0.5 seconds by default
return: Returns True successfully, and returns False if it fails
"""
# 使用示例 [Demo]
result = self.click_any_elements(["button/[8]","button/[9]","button/[10]"], 5, 0.5)
print(result)
def scroll_element(self, xpath: str, direction: int = 0) -》 bool:
"""
滚动元素
xpath: xpath 路径
direction: 滚动方向,0 向上滑动,1 向下滑动
return: 成功返回True 失败返回False
"""
# 使用示例 [Demo]
result = self.scroll_element("button/[8]", 0)
print(result)
def element_exists(self, xpath: str, wait_time: float = 5, interval_time: float = 0.5) -》 bool:
"""
元素是否存在
Does the element exist
xpath: xpath 路径
wait_time: 找不到元素等待时间,默认 5秒
interval_time: 找不到元素循环查找间隔时间,默认 0.5秒
return: 成功返回True 失败返回False
xpath: xpath path
wait_time: the waiting time, which is self.wait_timeout by default
interval_time: polling interval; self.interval_timeout is selected by default
return: Returns True successfully, and returns False if it fails
"""
# 使用示例 [Demo]
result = self.element_exists("button/[12]", 5, 0.5)
print(result)
def any_elements_exists(self, xpath_list: list, wait_time: float = 5, interval_time: float = 0.5) -》 bool:
"""
遍历列表中的元素是否存在
Traverse the elements in the list
xpath_list: xpath 列表
wait_time: 找不到元素等待时间,默认 5秒
interval_time: 找不到元素循环查找间隔时间,默认 0.5秒
return: 任意一个元素存在就返回 True 否则就是为False
xpath_list: xpath list
wait_time: the waiting time, which is self.wait_timeout by default
interval_time: polling interval; self.interval_timeout is selected by default
return: If any element exists, it will return True, otherwise it will be False
"""
# 使用示例 [Demo]
result = self.any_elements_exists(["button/[12]","button/[13]"], 5, 0.5)
print(result)
def element_is_selected(self, xpath: str) -》 bool:
"""
判断元素是否选中
Determine whether the element is selected
xpath: xpath 路径
return: 成功返回True 失败返回False
xpath: xpath path
return: Returns True successfully, and returns False if it fails
"""
# 使用示例 [Demo]
result = self.element_is_selected("button/[14]")
print(result)
def click_element_by_slide(self, xpath, distance: int = 1000, duration: float = 0.5, direction: int = 1,count: int = 999,
end_flag_xpath: str = None, wait_time: float = 600,interval_time: float = 0.5) -》 bool:
"""
滑动,查找并点击指定元素
Slide the list, find and click the specified element.
xpath: xpath路径
distance: 滑动距离,默认 1000
duration: 滑动时间,默认 0.5 秒
direction: 滑动方向,默认为 1; 1=上滑,2=下滑
count: 滑动次数 默认999
end_flag_xpath: 结束标志 xpath,无标志不检测此标志
wait_time: 找不到元素等待时间,默认 10 分钟
interval_time: 找不到元素循环查找间隔时间,默认 0.5秒
return: 成功返回True 失败返回False
Xpath: xpath path
Distance: sliding distance; default is 1000
Duration: sliding time, 0.5 seconds by default
Direction: sliding direction, which defaults to 1; 1= slide up, 2= slide down
Count: number of slides
End_flag_xpath: end the flag xpath, if there is no flag, this flag will not be detected
Wait_time: waiting time, 10 minutes by default
Interval_time: the polling interval, which is 0.5 seconds by default
return: Returns True successfully, and returns False if it fails
"""
# 使用示例 [Demo]
result = self.click_element_by_slide("button/[14]", 1000, 0.5, 1, 999, None, 600, 0.5)
print(result)
def get_elements(self) -》 json:
"""
获取可见区域内的所有元素信息
return: 成功返回数组json格式的元素信息,失败返回null
Get information of all elements in the visible area
return: element information in json format of array is returned successfully, and null is returned if it fails
"""
# 使用示例 [Demo]
result = self.get_elements()
print(result)