【发布时间】:2018-01-03 15:26:01
【问题描述】:
[上下文]
Appium 1.6.5
XCode 8.3.3
iOS 10.3
Python 2.7
我正在使用 Appium 试验一个基本的 iOS 应用程序,该应用程序是从 XCode 模板创建的,该模板创建一个选项卡式应用程序。 我的应用程序是根据该模板创建的,该模板本质上具有一个选项卡栏控制器,其中预先设置了 2 个选项卡。 每个选项卡显示不同的视图。 每个视图都有 2 个标签,上面有一些文字。
[目标]
我想编写一个导航到特定选项卡的 Appium 脚本,然后读取其中一个标签的文本。
[问题]
我能够定位到(包括)与所选选项卡对应的视图的元素。但是,我没有看到该视图内的任何元素。
我尝试同时使用 ID 和 XPATH,结果相同。
注意:我尝试访问的每个元素都启用了辅助功能并设置了辅助功能 ID。我设置的每个辅助功能 ID 都是唯一的。
[问题]
如何使用 Appium 访问相关标签?或者更好的是,我的观点中的任何元素?
[driver.page_source 的输出]
View1 是我的两个视图之一,正如您在上面的 XML 中看到的,它似乎不包含该视图中的任何标签:
[Python 代码]
这是我正在使用的代码:
driver = webdriver.Remote(get_appium_server(), desired_capabilities=get_capabilities())
driver.find_element_by_id('view1') # This works fine
driver.find_element_by_id('view1label1') # The code fails here despite the fact that this accessibility ID exists for one of the labels underneath 'view1'
当我运行它时,我得到以下错误:
Traceback (most recent call last):
File "/some_path/Appium.py", line 33, in <module>
mypythonappiumfunction()
File "/some_path/Appium.py", line 28, in mypythonappiumfunction
driver.find_element_by_id('view1label1') # The code fails here despite the fact that this accessibility ID exists for one of the labels underneath 'view1'
File "/some_path/robot/lib/python2.7/site-packages/selenium/webdriver/remote/webdriver.py", line 289, in find_element_by_id
return self.find_element(by=By.ID, value=id_)
File "/some_path/robot/lib/python2.7/site-packages/selenium/webdriver/remote/webdriver.py", line 791, in find_element
'value': value})['value']
File "/some_path/robot/lib/python2.7/site-packages/selenium/webdriver/remote/webdriver.py", line 256, in execute
self.error_handler.check_response(response)
File "/some_path/robot/lib/python2.7/site-packages/appium/webdriver/errorhandler.py", line 29, in check_response
raise wde
selenium.common.exceptions.NoSuchElementException: Message: An element could not be located on the page using the given search parameters.`
【问题讨论】:
标签: python python-2.7 appium-ios