メインコンテンツにスキップ

scrollIntoView

デスクトップ/モバイルWebとおよびモバイルネイティブアプリの両方でビューポート内に要素をスクロールします。

情報

モバイルネイティブアプリのスクロールはモバイルの swipe コマンドに基づいて行われます。

このコマンドは、以下の最新コンポーネントでのみ動作します:

  • Appiumサーバー(バージョン2.0.0以上)
  • appium-uiautomator2-driver(Android用)
  • appium-xcuitest-driver(iOS用)

互換性の問題を避けるため、ローカルまたはクラウドベースのAppium環境を定期的に更新してください。

パラメータ
名前タイプ詳細
options
省略可能
object, booleanElement.scrollIntoView()のオプション。デスクトップ/モバイルWebのデフォルト:
{ block: 'start', inline: 'nearest' }
モバイルネイティブアプリのデフォルト
{ maxScrolls: 10, scrollDirection: 'down' }
デスクトップ/モバイルWebのみ
options.behavior
省略可能
stringMDNリファレンスを参照してください。
WEBのみ (デスクトップ/モバイル)
options.block
省略可能
stringMDNリファレンスを参照してください。
WEBのみ (デスクトップ/モバイル)
options.inline
省略可能
stringMDNリファレンスを参照してください。
WEBのみ (デスクトップ/モバイル)
モバイルネイティブアプリのみ
options.direction
省略可能
stringdownupleftrightのいずれか。デフォルトは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')
});
});

Welcome! How can I help?

WebdriverIO AI Copilot