Playwright その他の API
この付録では、Dialog、Download、Video、Tracing などの補助クラスの API を一覧にします。
Dialog クラス
| メソッド | 説明 |
dialog.accept(promptText?) | ダイアログを確定 |
dialog.dismiss() | ダイアログをキャンセル |
dialog.message() | ダイアログメッセージ |
dialog.type() | ダイアログのタイプ:'alert' | 'confirm' | 'prompt' | 'beforeunload' |
dialog.defaultValue() | ダイアログのデフォルト入力値 |
dialog.page() | ダイアログが属するページ |
Download クラス
| メソッド | 説明 |
download.saveAs(path) | ファイルを指定パスに保存 |
download.suggestedFilename() | 推奨ファイル名を取得 |
download.url() | ダウンロード URL |
download.page() | 属するページ |
download.failure() | ダウンロード失敗情報(失敗がない場合は null を返す) |
download.delete() | ダウンロードしたファイルを削除 |
FileChooser クラス
| メソッド | 説明 |
fileChooser.setFiles(files, options?) | ファイルを選択 |
fileChooser.isMultiple() | 複数選択モードかどうか |
fileChooser.page() | 属するページ |
ConsoleMessage クラス
| メソッド | 説明 |
consoleMessage.type() | メッセージタイプ:'log' | 'error' | 'warning' | 'info' | 'debug' |
consoleMessage.text() | メッセージテキスト |
consoleMessage.location() | メッセージの発生位置 |
consoleMessage.args() | メッセージパラメータ(JSHandle 配列) |
Video クラス
| メソッド | 説明 |
video.saveAs(path) | ビデオをファイルに保存 |
video.delete() | ビデオファイルを削除 |
video.path() | ビデオファイルのパス |
Tracing クラス
| メソッド | 説明 |
tracing.start(options?) | Trace の記録を開始 |
tracing.startChunk(options?) | 新しい Trace ブロックを開始 |
tracing.stopChunk(options?) | Trace ブロックを停止して保存 |
tracing.stop(options?) | 記録を停止して Trace を保存 |
Clock クラス
| メソッド | 説明 |
clock.install(options?) | フェイククロックをインストール |
clock.pauseAt(time) | 指定時刻で一時停止 |
clock.resume() | 実行を再開 |
clock.setFixedTime(time) | 固定時刻を設定 |
clock.fastForward(time) | 時間を早送り |
clock.runFor(time) | 指定時間を実行 |
Selectors クラス
| メソッド | 説明 |
selectors.register(name, script, options?) | カスタムセレクターエンジンを登録 |
ElementHandle クラス
| メソッド | 説明 |
elementHandle.click(options?) | クリック |
elementHandle.fill(value) | テキストを入力 |
elementHandle.screenshot(options?) | 要素のスクリーンショット |
elementHandle.boundingBox() | 位置とサイズを取得 |
elementHandle.getAttribute(name) | 属性を取得 |
elementHandle.textContent() | テキストを取得 |
elementHandle.ownerFrame() | 属する Frame |
JSHandle クラス
| メソッド | 説明 |
jsHandle.evaluate(fn, arg?) | JS を実行 |
jsHandle.getProperty(name) | プロパティを取得 |
jsHandle.getProperties() | すべてのプロパティを取得 |
jsHandle.jsonValue() | JSON 値を取得 |
jsHandle.dispose() | リソースを解放 |
CDPSession クラス
| メソッド | 説明 |
cdpSession.send(method, params?) | CDP コマンドを送信 |
cdpSession.detach() | CDP セッションを分離 |
Worker クラス
| メソッド/イベント | 説明 |
worker.url() | Worker URL |
worker.evaluate(fn, arg?) | Worker 内で JS を実行 |
worker.on('close', handler) | Worker クローズイベント |
Frame クラス
| メソッド | 説明 |
frame.name() | Frame 名 |
frame.url() | Frame URL |
frame.goto(url, options?) | Frame ナビゲーション |
frame.locator(selector) | CSS/XPath ロケーター |
frame.getByRole(role, options?) | ロールによるロケーター |
frame.getByText(text) | テキストによるロケーター |
frame.evaluate(fn, arg?) | JS を実行 |
frame.content() | HTML コンテンツを取得 |
frame.parentFrame() | 親 Frame |
frame.childFrames() | 子 Frame のリスト |
エラークラス
| 类 | 説明 |
PlaywrightException | 一般的な Playwright 例外 |
TimeoutError | タイムアウトエラー(アサーションタイムアウト、操作タイムアウトなど) |
その他の拡張