Selenium WebDriver in Practice
Yujun Liang and Alex Collins
  • MEAP began July 2015
  • Publication in October 2016 (estimated)
  • ISBN 9781633430143
  • 350 pages (estimated)
  • printed in black & white
We regret that Manning Publications will not be publishing this title.
Selenium WebDriver in Practice is a hands-on guide to dozens of specific techniques you can use to get the most of WebDriver in your test automation development. Following a cookbook-style Problem/Solution/Discussion format, this practical handbook gives you instantly-useful solutions for important areas like interacting with and testing web applications and using the WebDriver APIs. As you read, you'll graduate from WebDriver fundamentals to must-have practices ranging from how to interact with, control and verify web pages and exception handling, to more complex interactions like page objects, alerts, and JavaScript, as well as integrating with Continuous Integration tools, mobile testing, and much more. By the end of the book, you’ll be confident and skilled at testing your web applications with WebDriver.
Table of Contents detailed table of contents

Part 1: Fundamentals

1. Introduction

1.1. What is WebDriver?

1.2. How WebDriver works

1.3. Why choose WebDriver?

1.4. What WebDriver cannot do

1.5. The history of Selenium

1.6. The tools you need to get started

1.6.1. Java Development Kit (JDK)

1.6.2. Apache Maven

1.6.3. Mozilla Firefox

1.7. The test project

1.8. "Hello WebDriver!"

1.9. Summary

2. Locating elements on a page

2.1. Locating one or more elements based on ID, class, or name

2.1.1. What is a search context?

2.1.2. What is a By locator?

2.1.3. ByLinkText and ByPartialLinkText

2.1.4. Technique 1: Creating a locator factory For complex locators

2.2. Fine-grained targeting using complex CSS selectors

2.2.1. Technique 2: Locating table cells using CSS selectors

2.2.2. Technique 3: Encapsulating table access within a Table class

2.3. The navigational pattern

2.3.1. Technique 4: Narrowing down by locating within chained SearchContexts

2.4. Locator composition

2.4.1. ByIdOrName

2.4.2. ByChained

2.4.3. Technique 5: Creating locator composers to provide backward/forward compatability

2.4.4. Organizing locators

2.4.5. Technique 6: Using enums to organize locators into cohesive groups

2.5. The finder pattern

2.6. Making pages amenable to element locating

2.6.1. Technique 7: Using a common CSS class prefix to create your own automation namespace

2.7. Summary

3. Interacting with elements on a page

3.1. Be the user

3.2. Entering text

3.2.1. Technique 8: Using sendKeys and getKeyboard to enter text into a form

3.2.2. Technique 9: Entering text into a WYSIWYG editor

3.3. Simulating user behavior using the mouse

3.3.1. Technique 10: Clicking and double-clicking with the mouse

3.4. Context menus

3.4.1. Technique 11: Opening a context menu

3.5. Interacting with forms

3.5.1. Password

3.5.2. Radio button

3.5.3. Single and multiple-choice select

3.6. Summary

4. Examining A Page

4.1. Checking whether an element is present

4.1.1. Technique 12: Using findElements to determine whether an element is present

4.2. Verifying whether an element is visible (or not)

4.2.1. Technique 13: Using isPresent to determine whether an element is visible

4.3. Verify the page title

4.3.1. Technique 14: Using getPageTitle to check the title of a page

4.4. Verifying that text is on the page

4.4.1. Technique 15: Using XPath and an element stream to verify that text is on the page

4.5. Examining an element's styling

4.5.1. Technique 16: Verifying an element's style using getCssValue

4.6. Summary

5. Making Maintainable Tests Using The Page Object Pattern

5.1. What is a page object?

5.2. Creating a page object for a login form

5.3. Fluent page objects using method chaining

5.4. Creating a page object for a whole page

5.5. What makes a great page object?

5.5.1. Don't expose WebDriver methods via public methods or fields

5.5.2. Model behavior rather than the underlying HTML

5.5.3. Be highly cohesive

5.5.4. Be lazy

5.5.5. Throw an error for the wrong page

5.5.6. Don't provide methods that assert

5.6. Using PageFactory and annotations to simplify your page objects

5.6.1. Technique 17: Using PageFactory to simplify code

5.7. Using LoadableComponent to make your page objects robust

5.7.1. Technique 18: Using LoadableComponent to make your page object robust

5.7.2. Technique 19: Creating a loading page factory

5.8. Summary

6. What To Do When Something Goes Wrong

6.1. Exceptions

6.2. Retrying when you can't find a slippery element

6.2.1. Technique 20: Retrying on exception

6.3. Understanding implicit waiting

6.4. Explicitly waiting for elements to load

6.4.1. Technique 21: Using WebDriverWait to wait for slippery elements

6.5. Internationalization

6.6. Summary

7. Managing WebDriver

7.1. Quitting the driver, even if the Java Virtual Machine crashes

7.2. Having a single place to supply drivers

7.2.1. Technique 23: Injecting a driver

7.3. Making code run using base URLs

7.3.1. Technique 24: Injecting a base URL

7.4. Taking a screenshot when a test finishes

7.4.1. Technique 25: Using the Spring test listener to take a screenshot when a test finishes

7.5. Summary

Part 2: WebDriver APIs In Depth

8. Windows, pop-ups, and frames

8.1. Finding the window a page opens

8.1.1. Dirty windows

8.1.2. Technique 26: Encapsulating window handling

8.2. Modal pop-ups

8.2.1. JavaScript pop-ups

8.2.2. HTTP authentication pop-ups

8.2.3. Synthetic pop-ups

8.2.4. Technique 27: Creating a Page Object for synthetic modals

8.2.5. System pop-ups

8.3. Inline frames

8.4. Summary

9. Unicorns and other beasts: Exotic features of web pages

9.1. Advanced user interaction with action chains

9.1.1. Technique 28: Lazy element for action chains

9.2. Advanced forms

9.2.1. Selecting multiple options

9.2.2. Uploading files

9.3. Examining HTTP cookies

9.4. Tooltips

9.4.1. Technique 29: Creating a tooltip extractor

9.5. Summary

10. Executing JavaScript using the JavascriptExecutor interface

10.1. Introduction to executing JavaScript

10.2. Using JavaScript to examine a page

10.2.1. Technique 30: Using JavaScript to verify that an image is loaded

10.3. Overriding built-in JavaScript APIs

10.4. Using JavaScript to test geolocation

10.4.1. Technique 31: Overriding JavaScript to control geolocation

10.5. Automating web notifications

10.5.1. Technique 32: Overriding JavaScript to capture a notification

10.6. Summary

11. What you need to know about different browsers

11.1. Comparing drivers

11.2. Self-signed certificates

11.3. Desktop browsers

11.4. Firefox

11.5. Chrome

11.5.1. Technique 30: Automatically downloading the driver binary

11.5.2. Technique 31: Mobile testing using Chrome’s mobile emulation

11.6. Internet Explorer

11.6.1. Technique 32: Using a Vagrant virtual machine to run IE

11.7. Microsoft Edge

11.8. Safari

11.9. Headless browsers

11.9.1. HtmlUnit

11.9.2. PhantomJS

11.9.3. XVFB: The X11 virtual frame buffer

11.10. iPhone, iPad, and Android - Appium

11.11. Summary

12. Wrapping WebDriver and WebElement

Part 3: Page Based Automation Framework

13. Forming A Framework

14. Encapsulating and Grouping elements

15. Automating a page flow

16. Handling HTML Tables

17. Automating jQuery Datepicker

18. Datepicker Framework

About the Technology

Web applications are difficult to test because so much depends on the way a user interacts with individual pages. The Selenium WebDriver web testing framework helps you build reliable and maintainable test automation for your web applications across multiple browsers, operating systems and programming languages. Much like a human, it can click on links, fill out forms, and read the web pages, and unlike a human, it does not get bored. WebDriver can do nearly anything you ask it to—the trick is to come up with a unified approach to testing. Fortunately, that’s where this book really shines.

What's inside

  • Specific, practical WebDriver techniques
  • Interacting with, controlling, and testing web applications
  • Using the WebDriver APIs
  • Making maintainable tests
  • Automated testing techniques

About the reader

This book assumes you’re comfortable reading code in Java or a similar language and that you know the basics of building and testing applications. No WebDriver experience is required.

About the authors

Yujun Liang is a Technical Agile Coach who teaches agile software development technologies including test automation using Selenium WebDriver. He used to work for ThoughtWorks and helped clients build automation testing for web applications with rich user interaction and complex business logic.


Alex Collins is a Technical Lead at Gamesys in the UK, a technology blogger, public speaker, and OSS contributor. Alex has been working with Selenium WebDriver since 2011.


Manning Early Access Program (MEAP) Read chapters as they are written, get the finished eBook as soon as it’s ready, and receive the pBook long before it's in bookstores.