AutomationElement.AutomationIdProperty 欄位

定義

識別用來識別元素的 AutomationId 屬性。

public: static initonly System::Windows::Automation::AutomationProperty ^ AutomationIdProperty;
public static readonly System.Windows.Automation.AutomationProperty AutomationIdProperty;
 staticval mutable AutomationIdProperty : System.Windows.Automation.AutomationProperty
Public Shared ReadOnly AutomationIdProperty As AutomationProperty 

欄位值

範例

下列範例會擷取 屬性的目前值。 如果專案未提供預設值,則會傳回預設值。

string autoId =
    autoElement.GetCurrentPropertyValue(AutomationElement.AutomationIdProperty) as string;
Dim autoId As String = _
    CStr(autoElement.GetCurrentPropertyValue(AutomationElement.AutomationIdProperty))

下列範例會擷取屬性的目前值,但指定如果專案本身未提供屬性的值, NotSupported 則會傳回 而不是預設值。

string autoIdString;
object autoIdNoDefault =
    autoElement.GetCurrentPropertyValue(AutomationElement.AutomationIdProperty, true);
if (autoIdNoDefault == AutomationElement.NotSupported)
{
    // TODO Handle the case where you do not wish to proceed using the default value.
}
else
{
    autoIdString = autoIdNoDefault as string;
}
Dim autoIdString As String
Dim autoIdNoDefault As Object = autoElement.GetCurrentPropertyValue(AutomationElement.AutomationIdProperty, True)
If autoIdNoDefault Is AutomationElement.NotSupported Then
    ' TODO Handle the case where you do not wish to proceed using the default value.
Else
    autoIdString = CStr(autoIdNoDefault)
End If

備註

使用者介面自動化用戶端應用程式會使用此識別碼。 使用者介面自動化提供者應該使用 中的 AutomationElementIdentifiers 對等識別碼。

您也可以從 CurrentCached 屬性擷取這個屬性。

屬性的傳回值的類型為 String 。 屬性的預設值是空字串。

當專案可供使用時, AutomationIdProperty 不論本機語言為何,應用程式的任何實例預期一律相同。 值在同層級元素之間應該是唯一的,但在整個桌面上不一定是唯一的。 例如,應用程式多個實例或 Microsoft Windows 檔案總管中的多個資料夾檢視可能包含具有相同 AutomationIdProperty 的元素,例如 「SystemMenuBar」。

雖然一律建議支援 , AutomationId 以取得更佳的可測試性,但這不是必要屬性。 支援的位置, AutomationId 適用于建立不論 UI 語言為何執行的測試自動化腳本。 用戶端不應假設 AutomationId 其他應用程式所公開的 。 AutomationId不一定保證在應用程式的不同版本或組建之間保持穩定。

使用者介面實例 (UI) 元素會依其 RuntimeIdProperty 屬性在桌面上唯一識別。

注意

所有控制項檢視中的 UI 自動化項目都支援 AutomationIdProperty,除了最上層的應用程式視窗、衍生自沒有識別碼或 x:Uid 的 Windows Presentation Foundation (WPF) 控制項的 UI 自動化元素,以及衍生自沒有控制項識別碼的 Win32 控制項的 UI 自動化元素以外。

適用於

另請參閱