参考@huanzhijin老师发布的 Appium Python 中文版 API https://testerhome.com/topics/3711,进行元素定位,点击
这是用 inspector 给出的 APP 里面要定位的元素的具体信息,如图:
find_element_by_accessibility_id
find_element_by_accessibility_id(self, id):
Finds an element by accessibility id.
通过accessibility id查找元素
:Args:
- id - a string corresponding to a recursive element search using the
Id/Name that the native Accessibility options utilize
:Usage:
driver.find_element_by_accessibility_id()
用法driver.find_element_by_accessibility_id(‘id’)
self.driver.find_element_by_accessibility_id('个人').click()
selenium.common.exceptions.WebDriverException: Message: An unknown server-side error occurred while processing the command. Original error: elementId 0 could not be tapped
find_element_by_xpath(self, xpath):
Finds element by xpath.
通过Xpath定位元素,详细方法可参阅http://www.w3school.com.cn/xpath/
:Args:
xpath - xpath of element to locate. "//input[@class='myelement']"
Note: The base path will be relative to this element's location.
This will select the first link under this element.
::
myelement.find_elements_by_xpath(".//a")
However, this will select the first link on the page.
::
myelement.find_elements_by_xpath("//a")
用法 find_element_by_xpath(“//*”)
self.driver.find_element_by_xpath("//UIAApplication[1]/UIAWindow[1]/UIATabBar[1]/UIAButton[4][contains(@text, '个人')]").click()
selenium.common.exceptions.NoSuchElementException: Message: An element could not be located on the page using the given search parameters.