我有一个列表视图,其中包含几个列表项。每个项目都是一个相对布局,它有一个图像按钮和一个嵌套线性布局,它有一个带有唯一文本的文本视图。我需要能够根据 textview 中的文本在列表中找到一个项目,然后单击它旁边的图像按钮。基于 UiAutomator API,看起来最好的方法是使用fromParent
允许您访问父视图的兄弟姐妹的方法。我滚动和查找文本视图没有问题,但我没有成功为其父视图或图像按钮创建 UiSelector。
self.web_driver.find_element_by_android_uiautomator('new UiScrollable(
new UiSelector().resourceId("' + self.id_prefix + 'list_view")).scrollIntoView(
new UiSelector().text("' + identifier + '")) ;')
self.web_driver.find_element_by_android_uiautomator('new UiSelector().fromParent(
new UiSelector().text("' + identifier + '"))')
第一次调用完美无缺,我知道选择器可以找到视图。问题是使用该 UiSelector 来获取父视图的 UiSelector。
堆栈跟踪
Traceback (most recent call last):
File "/.../test_suites/data_management.py", line 46, in test_delete
self.delete(valid)
File "/.../android_data_management.py", line 45, in delete
'list_view"))')
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/appium/webdriver/webdriver.py", line 110, in find_element_by_android_uiautomator
return self.find_element(by=By.ANDROID_UIAUTOMATOR, value=uia_string)
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/selenium/webdriver/remote/webdriver.py", line 712, in find_element
{'using': by, 'value': value})['value']
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/selenium/webdriver/remote/webdriver.py", line 201, in execute
self.error_handler.check_response(response)
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/appium/webdriver/errorhandler.py", line 29, in check_response
raise wde
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/appium/webdriver/errorhandler.py", line 24, in check_response
super(MobileErrorHandler, self).check_response(response)
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/selenium/webdriver/remote/errorhandler.py", line 194, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.NoSuchElementException: Message: An element could not be located on the page using the given search parameters.