一、启动Appium服务器
(地址比如:0.0.0.0:4723
)
image.png
二、开启UI自动化
在手机设置 -开发者中 勾选 使用UI Automation
image.png
三、用xcode运行WebDriverAgent
targets选择:WebDriverAgentRunner
点击Product->Test
运行到手机上 (这个时候xcode控制台打印有http地址,这个地址没用)
image.png
四、启动Appium Inspector查看元素
Remote Host:0.0.0.0
Remote Port:4723
{
"platformName": "iOS",
"appium:platformVersion": "iOS 17.6.1",
"appium:deviceName": "xsmax",
"appium:appPackage": "com.test.www",
"appium:udid": "00008020-0134r342341123",
"appium:app": "", //可以不填
"appium:xcodeOrgId": "W2131412"
}
image.png
五、python代码 注意地址也是(0.0.0.0:4723)
import time
from appium import webdriver
from selenium.webdriver.common.by import By
caps = {}
caps["platformName"] = "iOS"
caps["appium:platformVersion"] = "iOS 17.6.1"
caps["appium:deviceName"] = "xsmax"
caps["appium:appPackage"] = "com.test.www"
caps["appium:udid"] = "00008020-0134r342341123"
caps["appium:xcodeOrgId"] = "W2131412"
caps["appium:includeSafariInWebviews"] = True
caps["appium:newCommandTimeout"] = 5
caps["appium:connectHardwareKeyboard"] = True
driver = webdriver.Remote("http://0.0.0.0:4723/wd/hub", caps)
for letter in 'pyton':
try:
ell = driver.find_element(By.NAME, "生猪2505")
except Exception as e:
print('报错')
else:
print('没有报错')
ell.click()
time.sleep(3)
driver.quit()
image.png