Chapter 3. WebDriver Fundamentals

This chapter presents the elementary aspects of the Selenium WebDriver API. To that aim, we review first the different ways to create instances of the WebDriver hierarchy (e.g., ChromeDriver, EdgeDriver, FirefoxDriver, etc.). Also, we explore the main methods available in these objects. Among them, locating the different elements in a web page is essential. Thus, you will discover the possible locators, i.e., strategies to find the elements within a web page (called WebElement in the Selenium WebDriver API), such as by tag name, link text, HTML attribute (identifier, name, or class), CSS selector, or XPath. Another critical aspect of the Selenium WebDriver API covered in this chapter is the impersonation of user actions (i.e., automated interactions with web pages using the keyboard and mouse). The last part of this chapter presents the ability to wait for web elements. This feature is critical due to the dynamic and asynchronous nature of web applications.

Basic WebDriver Usage

This section covers three fundamental aspects related to WebDriver objects. First, we review the different ways to create them. Second, we study their basic operations. Finally, we analyze the different ways to dispose of these objects (typically at the end of a test, for closing the browser).

WebDriver Creation

As introduced in Chapter 2, to control browsers with Selenium WebDriver in Java, the first step is to create WebDriver instances. Thus, we need to create a ...

Get Hands-On Selenium WebDriver with Java now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.