Skip to Content
JavaによるSelenium WebDriverのハンズオン
book

JavaによるSelenium WebDriverのハンズオン

by Boni Garcia
March 2025
Intermediate to advanced
422 pages
6h 59m
Japanese
O'Reilly Media, Inc.
Content preview from JavaによるSelenium WebDriverのハンズオン

第4章. ブラウザに依存しない機能

この作品はAIを使って翻訳されている。ご意見、ご感想をお待ちしている:translation-feedback@oreilly.com

この章では、異なるウェブブラウザで相互運用可能な Selenium WebDriver の機能をレビューする。このグループの中で、関連する多目的特性は JavaScript を実行することである。また、Selenium WebDriver API はページとスクリプトのロードのタイムアウトを設定できる。もう一つの便利な機能は、ブラウザ画面のスクリーンショット、または指定された要素に対応する部分のみのスクリーンショットを作成することである。それから、WebDriverを使用して、ブラウザのサイズや位置、履歴、クッキーなど、制御されたブラウザのさまざまな側面を管理することができる。次にWebDriverは、ドロップダウン・リスト(HTMLセレクト・フィールドやデータ・リスト)、ナビゲーション・ターゲット(Windows、タブ、フレーム、iframe)、ダイアログ・ボックス(アラート、プロンプト、確認、モーダル・ダイアログ)など、特定のWeb要素を制御するための様々なアセットを提供する。最後に、Web ストレージを使用してローカルデータとセッションデータを扱い、イベントリスナーを実装し、Selenium WebDriver API によって提供される例外を使用する方法を発見する。

JavaScriptを実行する

JavaScriptは、、すべての主要ブラウザでサポートされている高水準プログラミング言語である。DOM操作、ユーザ対話、リモートサーバからのリクエスト/レスポンス処理、or正規表現など、様々な関数の中で、ウェブアプリケーションのクライアント、サーバ側でJavaScriptを使用することができる。テスト自動化にとって幸運なことに、Selenium WebDriverは任意のJavaScriptを注入し実行することができる。そのために、Selenium WebDriver API はJavascriptExecutor というインタフェースを提供している。表 4-1 に、このインタフェースで利用可能なパブリックメソッドを、同期スクリプト、ピンスクリプト、非同期スクリプトの 3 つに分類して紹介します。以下のサブセクションでは、詳細を説明し、さまざまな例を通してその使用方法を説明する。

表4-1. JavascriptExecutorのメソッド
カテゴリー メソッド 戻る 説明

同期スクリプト

executeScript(
    String script,
    Object... args)
Object

現在のページでJavaScriptコードを実行する。

スクリプトをピン留めする

pin(String
    script)
ScriptKey

JavaScriptの一部をWebDriverセッションにアタッチする。ピン留めされたスクリプトは、WebDriver セッションが生きている間、複数回使用できる。

unpin(ScriptKey
    key)
void

以前にピン留めされていたスクリプトを WebDriver セッションにデタッチする。

getPinnedScripts()
Set<ScriptKey>

ピン留めされたすべてのスクリプトを収集する(各スクリプトは一意のScriptKey で識別される)。

executeScript(
    
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.

Read now

Unlock full access

More than 5,000 organizations count on O’Reilly

AirBnbBlueOriginElectronic ArtsHomeDepotNasdaqRakutenTata Consultancy Services

QuotationMarkO’Reilly covers everything we've got, with content to help us build a world-class technology community, upgrade the capabilities and competencies of our teams, and improve overall team performance as well as their engagement.
Julian F.
Head of Cybersecurity
QuotationMarkI wanted to learn C and C++, but it didn't click for me until I picked up an O'Reilly book. When I went on the O’Reilly platform, I was astonished to find all the books there, plus live events and sandboxes so you could play around with the technology.
Addison B.
Field Engineer
QuotationMarkI’ve been on the O’Reilly platform for more than eight years. I use a couple of learning platforms, but I'm on O'Reilly more than anybody else. When you're there, you start learning. I'm never disappointed.
Amir M.
Data Platform Tech Lead
QuotationMarkI'm always learning. So when I got on to O'Reilly, I was like a kid in a candy store. There are playlists. There are answers. There's on-demand training. It's worth its weight in gold, in terms of what it allows me to do.
Mark W.
Embedded Software Engineer

You might also like

データサイエンスのための実践線形代数

データサイエンスのための実践線形代数

Mike X Cohen
サイトリライアビリティワークブック ―SREの実践方法

サイトリライアビリティワークブック ―SREの実践方法

Betsy Beyer, Niall Richard Murphy, David K. Rensin, Kent Kawahara, Stephen Thorne, 澤田 武男, 関根 達夫, 細川 一茂, 矢吹 大輔, 玉川 竜司
エンジニアが学ぶ会計システムの「知識」と「技術」

エンジニアが学ぶ会計システムの「知識」と「技術」

広川 敬祐, 五島 伸二, 小田 恭彦, 大塚 晃, 川勝 健司

Publisher Resources

ISBN: 9798341626287