appium-inspector
appium-server
aapt
一、Appium定位元素
⼿机端界⾯⽂件的格式规范是xml,它虽然和Html不⼀样,但是对于我们 理解元素和理解属性来说是⼀样的
属性定位:
属性 | 定位⽅式 | 示例 |
content-desc | Accessibility ID | driver.find_element(By.ACCESSIBILITY_ID, "书城") |
Class name Tag Name | Class name | driver.find_elements(By.CLASS_NAME, "android.widget.TextView") |
resource-id(andriod) | ID | driver.find_elements(By.ID, "com.zhao.myreader:id/civ_avatar") |
name (ios) | ID | driver.find_element(By.ID, "com.zhao.myreader:id/iv_search") |
路径定位:
- xpath
二、Appium元素操作
driver.find_element(By.ID, "xxxxx")
.click()
.send_keys()
. screenshot()
.back()
.swipe(700, 1700, 700, 500)
save_screenshot
ele.click() # 点击
ele.send_keys() # 输⼊
ele.screenshot() # 截图
ele.set_value() # 输⼊ value 与 send_keys相同
le.set_text() # 输⼊ text 与 send_keys相同
ele.find_element(, ) # 元素内定位
三、等待
强制,隐式,显式
driver.wait_activity(<活动名>,<超时时间>,<频率时间>)
四、设备操作
TouchAction-单指操作
- touch_action = TouchAction(driver)
- touch_action.long_press(el=ele, duration=2000) # ⻓按
- touch_action.release() # 释放
- touch_action.perform()
MultiAction-多指操作
# 单指操作1
touch_action1 = TouchAction(driver)
touch_action1.long_press(x=550, y=880).move_to(x=140, y=380)
# 单指操作2
touch_action2 = TouchAction(driver)
touch_action2.long_press(x=550, y=900).move_to(x=1000, y=2000)
# 多指合并
multi_action = MultiAction(driver)
multi_action.add(touch_action1)
multi_action.add(touch_action2)
multi_action.perform()
# 导包
from selenium.webdriver.common.action_chains import ActionChains
from selenium.webdriver.common.actions import interaction
from selenium.webdriver.common.actions.action_builder import ActionBuilder
from selenium.webdriver.common.actions.pointer_input import PointerInput
actions = ActionChains(driver)
pointer = PointerInput(interaction.POINTER_MOUSE, "mouse") # 使⽤⿏标事件
actions.w3c_actions = ActionBuilder(driver, mouse=pointer) # 定义事件对象
actions.w3c_actions.pointer_action.move_to(<origin_el: element object>)
# 移动⿏标⾄某元素对象
actions.w3c_actions.pointer_action.pointer_down() # 按下⿏标
actions.w3c_actions.pointer_action.pause(<time:int>) # 动作暂停时间
actions.w3c_actions.pointer_action.move_to(<destination_el: element object>) # 移动⿏标⾄某元素对象
actions.w3c_actions.pointer_action.pause(<time:int>) # 动作暂停时间
actions.w3c_actions.pointer_action.release() # 释放⿏标
actions.perform() # 时间执⾏