测试环境

场景

参考@huanzhijin老师发布的 Appium Python 中文版 API https://testerhome.com/topics/3711,进行元素定位,点击

这是用 inspector 给出的 APP 里面要定位的元素的具体信息,如图:

问题描述

1. find_element_by_accessibility_id

文章里的说明
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()
Error
selenium.common.exceptions.WebDriverException: Message: An unknown server-side error occurred while processing the command. Original error: elementId 0 could not be tapped

2. find_element_by_xpath

文章里的说明
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()
Error
selenium.common.exceptions.NoSuchElementException: Message: An element could not be located on the page using the given search parameters.

几个疑问

  1. find_element_by_accessibility_id 里面的 ‘id’ 是 ‘name’ 吗,不是的话是哪个
  2. @huanzhijin前辈的文章中给出了好些个定位元素的方法,哪些是在 iOSAPP 上常用的
  3. 说个题外话,这样排版可以吗?逛 testerhome 很久了,最近才注册,第一次发帖,有没有注意到的地方,还请大家指正!


↙↙↙阅读原文可查看相关链接,并与作者交流