scrollIntoView
デスクトップ/モバイルWebとおよびモバイルネイティブアプリの両方でビューポート内に要素をスクロールします。
情報
モバイルネイティブアプリのスクロールはモバイルの swipe コマンドに基づいて行われます。
このコマンドは、以下の最新コンポーネントでのみ動作します:
- Appiumサーバー(バージョン2.0.0以上)
appium-uiautomator2-driver(Android用)appium-xcuitest-driver(iOS用)
互換性の問題を避けるため、ローカルまたはクラウドベースのAppium環境を定期的に更新してください。
パラメータ
| 名前 | タイプ | 詳細 |
|---|---|---|
options省略可能 | object, boolean | Element.scrollIntoView()のオプション。デスクトップ/モバイルWebのデフォルト:{ block: 'start', inline: 'nearest' } モバイルネイティブアプリのデフォルト { maxScrolls: 10, scrollDirection: 'down' } |
| デスクトップ/モバイルWebのみ | ||
options.behavior省略可能 | string | MDNリファレンスを参照してください。 WEBのみ (デスクトップ/モバイル) |
options.block省略可能 | string | MDNリファレンスを参照してください。 WEBのみ (デスクトップ/モバイル) |
options.inline省略可能 | string | MDNリファレンスを参照してください。 WEBのみ (デスクトップ/モバイル) |
| モバイルネイティブアプリのみ | ||
options.direction省略可能 | string | down、up、left、rightのいずれか。デフォルトはupです。モバイルネイティブアプリのみ |
options.maxScrolls省略可能 | number | 要素を検索するためのスクロールの最大回数。デフォルトは10です。モバイルネイティブアプリのみ |
options.duration省略可能 | number | スワイプのミリ秒単位の持続時間。デフォルトは1500ミリ秒です。値が低いほど、スワイプが速くなります。モバイルネイティブアプリのみ |
options.scrollableElement省略可能 | Element | スクロールに使用される要素。要素が指定されていない場合、iOSでは-ios predicate string:type == "XCUIElementTypeApplication"、Androidでは//android.widget.ScrollView'というセレクタが使用されます。デフォルトセレクタに複数の要素が一致する場合、デフォルトでは最初に一致する要素が選択されます。モバイルネイティブアプリのみ |
options.percent省略可能 | number | スワイプする(デフォルトの)スクロール可能要素の割合。これは0から1の間の値です。デフォルトは0.95です。絶対に画面の上|下|左|右から正確にスワイプしないでください。通知バーなどのOSやアプリの機能が起動し、予期しない結果につながる可能性があります。 モバイルネイティブアプリのみ |
例
desktop.mobile.web.scrollIntoView.js
it('should demonstrate the desktop/mobile web scrollIntoView command', async () => {
const elem = await $('#myElement');
// scroll to specific element
await elem.scrollIntoView();
// center element within the viewport
await elem.scrollIntoView({ block: 'center', inline: 'center' });
});
mobile.native.app.scrollIntoView.js
it('should demonstrate the mobile native app scrollIntoView command', async () => {
const elem = await $('#myElement');
// scroll to a specific element in the default scrollable element for Android or iOS for a maximum of 10 scrolls
await elem.scrollIntoView();
// Scroll to the left in the scrollable element called '#scrollable' for a maximum of 5 scrolls
await elem.scrollIntoView({
direction: 'left',
maxScrolls: 5,
scrollableElement: $('#scrollable')
});
});