2016-09-28 68 views
0

在XCode 7.2中,如果我能得到XCUIApplication()。scrollViews [「Foo」] .otherElements.otherElements [「Page Title」],那麼說「給我這個名爲」Foo「的scrollView的頁面標題, ?」如何獲取Xcode 7.2 XCTestCase中滾動視圖的標籤?

我試過要求accessibilityLabel和staticTexts。我嘗試添加XCUIApplication()。scrollViews [「Foo」],XCUIApplication()。scrollViews [「Foo」]。otherElements等到我的觀察名單,但我沒有看到任何有用的信息。

當我做XCUIApplication().scrollViews["Foo"].otherElements一個po,我得到:

<snip> 
↪︎Find: Descendants matching type Other 
Output: { 
     Other 0x7f904b60e910: traits: 8589934592, {{0.0, 0.0}, {768.0, 1024.0}}, label: 'PDF article' 
     Other 0x7f9049efb6e0: traits: 8589934592, {{0.0, 0.0}, {768.0, 1024.0}} 
    } 

(在這種情況下,頁面標題爲「PDF文章」)

所以我覺得我應該能夠訪問它至少staticTexts。

回答

0

它看起來像你的頁面標題是不從UILabel繼承的自定義視圖(UILabel後裔標記爲StaticTexts)。

您需要在應用的代碼中爲您的頁面標題設置一個輔助功能標識(不是標籤)。

pageTitle.accessibilityIdentifier = "Page Title" 

這應該讓你的代碼工作,並且是最好的做法。

或者,如果您更改搜索鏈以使用標籤的值而不是"Page Title",那也應該起作用。但是,如果您打開具有不同標題的其他頁面,則這不起作用。

XCUIApplication().scrollViews["Foo"].otherElements["PDF article"] 
相關問題