Appium IOS自动化锁屏与解锁

from appium import webdriver

from time import sleep

from appium.webdriver.common.appiumby import AppiumBy

from appium.webdriver.common.touch_action import TouchAction

from selenium.webdriver.common.by import By

from selenium.webdriver.support import expected_conditions as EC

desired_capabilities = {

"platformName": "ios",

"appium:deviceName": "iPhone Jeff",

"appium:platformVersion": "16.5.1",

"appium:bundleId": "welab.bank.mobile.stage",

"appium:udid": "00008030-000A09C81A43802E"

}

desired_capabilities1 = {

"platformName": "ios",

"appium:deviceName": "iPhone 13",

"appium:platformVersion": "16.6",

"appium:bundleId": "welab.bank.mobile.stage",

"appium:udid": "00008110-000235E022EA201E"

}

driver = webdriver.Remote(command_executor='http://127.0.0.1:4723/wd/hub',

desired_capabilities=desired_capabilities1)

sleep(10)

ele = driver.find_element(AppiumBy.IOS_PREDICATE, "name == '用戶名稱'")

label == "用戶名稱" AND name == "用戶名稱" AND value == "用戶名稱"

//XCUIElementTypeStaticText[@name="用戶名稱"]

ele.send_keys("qatest101")

print(ele.location)

driver.find_element(By.ID, "")

# iOS自动化测试元素定位的accessibility_id主要使用元素的label或name(两个属性的值都一样)属性进行定位。

driver.find_element(AppiumBy.ACCESSIBILITY_ID, "密碼").send_keys("Aa123456")

sleep(2)

driver.hide_keyboard()

sleep(1)

driver.find_element(AppiumBy.ACCESSIBILITY_ID, "登入").click()

sleep(10)

driver.lock()

sleep(2)

try:
driver.unlock() # 如果有密码,这句会fail,但是会点亮屏幕,并且展示密码输入的页面

except:

pass

sleep(5)

driver.find_element(AppiumBy.XPATH, '//XCUIElementTypeKey[@name="2"]').click()

driver.find_element(AppiumBy.XPATH, '//XCUIElementTypeKey[@name="3"]').click()

driver.find_element(AppiumBy.XPATH, '//XCUIElementTypeKey[@name="6"]').click()

driver.find_element(AppiumBy.XPATH, '//XCUIElementTypeKey[@name="5"]').click()

driver.find_element(AppiumBy.XPATH, '//XCUIElementTypeKey[@name="8"]').click()

driver.find_element(AppiumBy.XPATH, '//XCUIElementTypeKey[@name="9"]').click()

ele_2 = driver.find_element(AppiumBy.XPATH, '//XCUIElementTypeKey[@name="2"]')

ele_3 = driver.find_element(AppiumBy.XPATH, '//XCUIElementTypeKey[@name="3"]')

TouchAction(driver).press(ele_2,ele_2.location.get("x"),ele_2.location.get("x")).wait(190).\

move_to(ele_2, ele_3.location.get("x"), ele_3.location.get("y")).perform().release()

sleep(5)

https://www.kancloud.cn/testerhome/appium_docs_cn/2001743

参考 External Libraries.site-packages.appium.webdriver.common.appiumby

class AppiumBy(By):

IOS_PREDICATE = '-ios predicate string'

IOS_UIAUTOMATION = '-ios uiautomation'

IOS_CLASS_CHAIN = '-ios class chain'

ANDROID_UIAUTOMATOR = '-android uiautomator'

ANDROID_VIEWTAG = '-android viewtag'

ANDROID_DATA_MATCHER = '-android datamatcher'

ANDROID_VIEW_MATCHER = '-android viewmatcher'

Deprecated

WINDOWS_UI_AUTOMATION = '-windows uiautomation'

ACCESSIBILITY_ID = 'accessibility id'

IMAGE = '-image'

CUSTOM = '-custom'

参考selenium

class By:

"""Set of supported locator strategies."""

ID = "id"

XPATH = "xpath"

LINK_TEXT = "link text"

PARTIAL_LINK_TEXT = "partial link text"

NAME = "name"

TAG_NAME = "tag name"

CLASS_NAME = "class name"

CSS_SELECTOR = "css selector"

相关推荐
Daniel_Coder41 分钟前
iOS Widget 开发-9:可配置 Widget:使用 IntentConfiguration 实现参数选择
ios·swiftui·swift·widget·intents
非专业程序员Ping3 小时前
Vibe Coding 实战!花了两天时间,让 AI 写了一个富文本渲染引擎!
ios·ai·swift·claude·vibecoding
00后程序员张6 小时前
HTTP抓包工具推荐,Fiddler配置方法、代理设置与使用教程详解(开发者必学网络调试技巧)
网络·http·ios·小程序·fiddler·uni-app·webview
Digitally6 小时前
如何从iPhone向Android 发送视频?8 种方法
iphone
2501_940094026 小时前
iphone Delta模拟器如何从夸克网盘导入游戏ROM 附游戏资源下载
游戏·ios·iphone
2501_9400940214 小时前
iPhone Delta模拟器游戏资源包合集中文游戏ROM+BIOS+Delta皮肤附游戏导入教程
游戏·ios·iphone
2501_9159184114 小时前
HTTP和HTTPS工作原理、安全漏洞及防护措施全面解析
android·http·ios·小程序·https·uni-app·iphone
白玉cfc14 小时前
【iOS】UICollectionView
macos·ios·cocoa
2501_9160074715 小时前
如何在 Windows 电脑上调试 iOS 设备上的 Safari?完整方案与实战经验分享
android·windows·ios·小程序·uni-app·iphone·safari
2501_9159184116 小时前
uni-app iOS日志管理实战,从调试控制台到系统日志的全链路采集与分析指南
android·ios·小程序·https·uni-app·iphone·webview