我有一个包含多个列表项的列表视图。每个项目都是一个相对布局,其中包含一个图像按钮和一个嵌套的线性布局,其中的文本视图具有唯一的文本。我需要能够根据textview中的文本在列表中找到一个项目,然后单击它旁边的图像按钮。基于UiAutomator API,看起来最好的方法是使用fromParent
方法,它允许您访问父视图的兄弟姐妹。滚动和查找textview没有问题,但是我没有成功为其父视图或图像按钮创建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。
UiSelector API, fromParent method
堆栈跟踪
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.
答案 0 :(得分:0)
我遇到过这个问题而且我的解决方案没有使用UI自动化脚本,但如果它适用于您,请尝试一下。