界面上有很多相同元素,通过索引点击对应的元素(如AAP上商品列表中的添加购物车按钮,点击指定商品的添加购物车按钮),可在..\AppiumLibrary\keywords\__element.py文件中添加如下代码:

def click_by_index(self, locator,index):
"""Click element identified by `locator` and `index`.

Key attributes for arbitrary elements are `index` and `name`.
See`introduction` for details about locating elements.
Args:
- ``locator`` - find elements by locator
- ``index`` - click the element with index
"""
self._info("Clicking element '%s'." % locator)
self._element_find(locator, False, True)[int(index)].click()

posted on 2019-09-12 09:38  nyli  阅读(174)  评论(0编辑  收藏  举报