動的呼び出しを使うと、モバイル ネイティブ アプリに対して Appium WebDriver のメソッドを直接呼び出すことができます。これは、Appium WebDriver のメソッドが Silk4NET API を介して公開されていない場合に有用です。
オブジェクトの複数の動的メソッドは InvokeMethods メソッドを使用して呼び出します。コントロールでサポートされている動的メソッドのリストを取得するには、GetDynamicMethodList メソッドを使用します。
プリミティブ型 (int など) とオブジェクト タイプ (java.lang.Integer など) の両方がサポートされます。プリミティブ型は必要に応じて拡大変換されます。たとえば、int が必要な場所で long を渡すことができます。
列挙パラメータは文字列として渡す必要があります。文字列は、列挙値の名前と一致しなければなりません。たとえば、メソッドが列挙型 ScreenOrientation のパラメータを必要とする場合、次の文字列値を使用できます: LANDSCAPE、PORTRAIT。
リスト、配列、または可変長引数のパラメータを持つメソッドを呼び出すことができます。リストの要素がターゲットの配列型に代入可能の場合、配列型への変換は自動的に行われます。
次のサンプル コードには、動的呼び出しを使用する共通の例を示します。
' VB .NET code
' Getting the page source
Dim pageSource As String = _desktop.MobileDevice("//MobileDevice").Invoke("getPageSource")
' Resetting an app
_desktop.MobileDevice("//MobileDevice").Invoke("resetApp")
' Changing the device orientation
_desktop.MobileDevice("//MobileDevice").Invoke("rotate", "LANDSCAPE")
_desktop.MobileDevice("//MobileDevice").Invoke("rotate", "PORTRAIT")
' Dynamic invoke on MobileObject (calls get redirected to the underlying web element for WebDriver)
With _desktop.MobileDevice("//MobileDevice")
.MobileObject("CheckBox 2").Invoke("click")
End With
// C#
MobileDevice device = _desktop.MobileDevice("//MobileDevice");
// Getting the page source
var pageSource = (string) device.Invoke("getPageSource");
// Resetting an app
device.Invoke("resetApp");
// Changing the device orientation
device.Invoke("rotate", "LANDSCAPE");
device.Invoke("rotate", "PORTRAIT");
// Dynamic invoke on MobileObject (calls get redirected to the underlying web element for WebDriver)
device.MobileObject("//MobileObject[@caption='CheckBox 2']").Invoke("click");