Appium在iOS上无法使用辅助功能ID属性来定位和访问元素的问题可以通过以下解决方法来解决:
示例代码:
from appium import webdriver
desired_caps = {
"platformName": "iOS",
"platformVersion": "12.1",
"deviceName": "iPhone 8",
"automationName": "XCUITest",
"app": "/path/to/your/app"
}
driver = webdriver.Remote("http://localhost:4723/wd/hub", desired_caps)
element = driver.find_element_by_xpath("//XCUIElementTypeButton[@name='Login']")
element.click()
driver.quit()
示例代码:
from appium import webdriver
desired_caps = {
"platformName": "iOS",
"platformVersion": "12.1",
"deviceName": "iPhone 8",
"automationName": "XCUITest",
"app": "/path/to/your/app"
}
driver = webdriver.Remote("http://localhost:4723/wd/hub", desired_caps)
element = driver.find_element_by_name("Login")
element.click()
driver.quit()
通过以上两种方法,您可以成功定位和访问iOS上的元素,即使辅助功能ID属性无法使用。请根据您的实际情况选择适合的定位方法。