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のハンズオン

第3章 WebDriverの基礎 WebDriverの基礎

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

この章では、Selenium WebDriver API の初歩的な側面を紹介する。この目的のために、WebDriver 階層のインスタンス(例えば、ChromeDriverEdgeDriverFirefoxDriver など)を作成するさまざまな方法を最初にレビューする。また、これらのオブジェクトで利用可能な主なメソッドを探索する。その中でも、Webページ内のさまざまな要素を見つけることは重要である。したがって、タグ名、リンクテキスト、HTML 属性(識別子、名前、クラス)、CSS セレクタ、XPath などの、可能なロケータ、すなわち、Web ページ内の要素を発見するための戦略(Selenium WebDriver API ではWebElement と呼び出し)を発見する。この章で扱われる Selenium WebDriver API のもう一つの重要な側面は、ユーザ操作のなりすまし(すなわち、キーボードとマウスを使った Web ページとの自動対話)である。この章の最後では、ウェブ要素を待つ機能を紹介する。この機能は、ウェブアプリケーションの動的で非同期な性質のために重要である。

WebDriverの基本的な使い方

このセクションでは、 WebDriver オブジェクトに関する3つの基本的な側面を取り上げる。まず、オブジェクトを作成するさまざまな方法について説明する。次に、オブジェクトの基本的な演算子について学ぶ。最後に、これらのオブジェクトを破棄するさまざまな方法を分析する(一般的には、エンドツーエンドテストでブラウザを閉じるとき)。

WebDriverの作成

第2章で紹介したように、JavaのSelenium WebDriverでブラウザを制御するために、最初の ステップは、WebDriver インスタンスを作成することである。したがって、 Chromeを使う場合はChromeDriver 、Edgeの場合はEdgeDriver 、Firefoxの場合はFirefoxDriver 、といったようにオブジェクトを作成する必要がある。これらの型のインスタンスを作成する基本的な方法は、Javaでnew 演算子を使うことである。例えば、 ChromeDriver オブジェクトを以下のように作成する:

WebDriver driver = new ChromeDriver();

WebDriver 、インスタンス作成に演算子new を使用することは完全に正しい。とはいえ、オブジェクトを作成する際の具体的な使用例によって、さらなる利点が得られる可能性がある他の方法についても検討する価値がある。WebDriver ビルダーと WebDriverManager ビルダーだ。

WebDriverビルダー

Selenium WebDriver API は WebDriver インスタンスを作成するためのビルダーパターンに従った組み込みメソッドを提供する。この機能はRemoteWebDriver クラスの静的メソッドbuilder() からアクセスでき、 はWebDriver オブジェクトを作成するための流暢な API を提供する。表3-1に、このビルダーで利用可能なメソッドを示す。例 3-1は、WebDriver ビルダーを使ったテストの雛形を示している。 ...

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