[語境]
Appium 1.6.5
的XCode 8.3.3
的iOS 10.3
的Python 2.7Appium - 無法看到內部視圖元素在一個標籤欄控制器
我正在與Appium試驗與從創建選項卡式應用程序的XCode模板創建的基本iOS應用程序。 我的應用程序是從該模板創建的,該模板基本上具有預設了2個選項卡的選項卡欄控制器。 每個選項卡顯示不同的視圖。每個視圖都有2個標籤,其上有一些文字。
[目標]
我想寫一個劇本Appium導航到一個特定的標籤,然後讀取一個標籤的文本。
[問題]
我能夠找到的元素最多(並且包括)對應於所選擇的標籤的圖。但是,我沒有看到那個視圖中的任何元素。
我試圖使用ID和XPATH的結果相同。
注意:我嘗試訪問的每個元素都啓用了輔助功能,並設置了輔助功能ID。我設置的每個輔助功能ID都是唯一的。
[問題]
如何使用Appium訪問有問題的標籤?甚至更好,我的觀點的任何元素?
[driver.page_source的輸出]
<?xml version="1.0" encoding="UTF-8"?><AppiumAUT><XCUIElementTypeApplication type="XCUIElementTypeApplication" name="MyTestApp" label="MyTestApp" enabled="true" visible="true" x="0" y="0" width="375" height="667"> <XCUIElementTypeWindow type="XCUIElementTypeWindow" enabled="true" visible="true" x="0" y="0" width="375" height="667"> <XCUIElementTypeOther type="XCUIElementTypeOther" enabled="true" visible="true" x="0" y="0" width="375" height="667"> <XCUIElementTypeOther type="XCUIElementTypeOther" enabled="true" visible="true" x="0" y="0" width="375" height="667"> <XCUIElementTypeOther type="XCUIElementTypeOther" enabled="true" visible="true" x="0" y="0" width="375" height="667"> <XCUIElementTypeOther type="XCUIElementTypeOther" name="view1" enabled="true" visible="true" x="0" y="0" width="375" height="667"/> </XCUIElementTypeOther> </XCUIElementTypeOther> <XCUIElementTypeTabBar type="XCUIElementTypeTabBar" enabled="true" visible="true" x="0" y="618" width="375" height="49"/> </XCUIElementTypeOther> </XCUIElementTypeWindow> <XCUIElementTypeWindow type="XCUIElementTypeWindow" enabled="true" visible="false" x="0" y="0" width="375" height="667"> <XCUIElementTypeOther type="XCUIElementTypeOther" enabled="true" visible="false" x="0" y="0" width="375" height="667"/> </XCUIElementTypeWindow> <XCUIElementTypeWindow type="XCUIElementTypeWindow" enabled="true" visible="true" x="0" y="0" width="375" height="667"> <XCUIElementTypeStatusBar type="XCUIElementTypeStatusBar" enabled="true" visible="true" x="0" y="0" width="375" height="20"> <XCUIElementTypeOther type="XCUIElementTypeOther" enabled="true" visible="false" x="0" y="0" width="375" height="20"/> <XCUIElementTypeOther type="XCUIElementTypeOther" enabled="true" visible="true" x="0" y="0" width="375" height="20"> <XCUIElementTypeOther type="XCUIElementTypeOther" enabled="true" visible="true" x="6" y="0" width="39" height="20"/> <XCUIElementTypeOther type="XCUIElementTypeOther" value="SSID" name="3 of 3 Wi-Fi bars" label="3 of 3 Wi-Fi bars" enabled="true" visible="true" x="50" y="0" width="13" height="20"/> <XCUIElementTypeOther type="XCUIElementTypeOther" name="10:35 AM" label="10:35 AM" enabled="true" visible="true" x="161" y="0" width="56" height="20"/> <XCUIElementTypeOther type="XCUIElementTypeOther" name="-100% battery power" label="-100% battery power" enabled="true" visible="true" x="337" y="0" width="33" height="20"/> </XCUIElementTypeOther> </XCUIElementTypeStatusBar> </XCUIElementTypeWindow> </XCUIElementTypeApplication></AppiumAUT>
視圖1是我的兩個觀點之一,你可以在上面的XML看,它似乎並沒有包含任何標籤的該視圖:
<XCUIElementTypeOther type="XCUIElementTypeOther" name="view1" enabled="true" visible="true" x="0" y="0" width="375" height="667"/>
[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.`