Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Free Learning
Arrow right icon
Selenium WebDriver Quick Start Guide
Selenium WebDriver Quick Start Guide

Selenium WebDriver Quick Start Guide: Write clear, readable, and reliable tests with Selenium WebDriver 3

eBook
€8.99 €19.99
Paperback
€24.99
Subscription
Free Trial
Renews at €18.99p/m

What do you get with eBook?

Product feature icon Instant access to your Digital eBook purchase
Product feature icon Download this book in EPUB and PDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want
OR
Modal Close icon
Payment Processing...
tick Completed

Billing Address

Table of content icon View table of contents Preview book icon Preview Book

Selenium WebDriver Quick Start Guide

Understanding the Document Object Model and Creating Customized XPaths

In the previous chapter, we had a look at Selenium RC, WebDriver, the basic Eclipse setup, and a very simple program. Opening the browser and loading a web page is OK to start with but it is not of much use if one is not able to do operations such as clicking links and buttons, selecting values from dropdowns, entering text in a textbox, and so on. In order to achieve this, we have to explore what is called the Document Object Model (DOM). The following topics will be covered in this chapter:

  • What is the DOM?
  • DOM traversal
  • What is the Fillo API?
  • Debugging in Eclipse

The four major topics will be explained in detail in the form of sub-topics throughout the chapter.

Technical requirements

What is the DOM?

The DOM is an application programming interface that is linked to HTML, XHTML, or XML documents and treats these similar to a tree where each node in the tree represents a part of the document.

In simple words, the DOM can be compared to a tree where there is a root node, intermediate nodes, and leaf nodes.

The root node has no parent; the intermediate nodes have a parent, one or more siblings, and one or more children. This is a very important concept and will help at the time of creating relative or customized XPaths, which we will see in a later part of the chapter.

Shown here is a sample DOM:

In the preceding diagram, there are three leaf nodes, two intermediate nodes, and one root node. All of this is contained in a document. The question that arises next is: how do we get to a particular node in this tree structure? This is where terms such as XPath and...

DOM traversal

Now that we have seen the basic definitions of XPaths and CSS and also looked at what WebElements are, let's understand how we can use these to exploit the DOM. DOM traversal entails getting to the desired element with the help of either XPaths or CSS. It is possible to traverse the DOM in a forward and backward direction with XPaths but traversal through XPaths is slow compared to CSS. Traversal using CSS can only be done in the forward direction. In order to traverse the DOM, using either XPaths or CSS, we need to understand the By class.

Dissecting the By class

The By class is an abstract class that has eight static methods and eight inner classes. Let's understand the structure of the By class.

...

Introducing the Fillo API

In the subsequent chapters, we will be dealing with a lot Excel data. In order to make data manipulation simpler using Excel, Codoid, a software firm, introduced the Fillo API. This API can be used for both XLS and XLSX files. It's an open source API. Fillo can be used to trigger select, insert, and update operations with where conditions. It also supports like and multiple where conditions. Let's understand how to make use of this useful API. First of all, let's add the Maven dependency for Fillo. Put the dependency shown here in pom.xml:

<dependency>
<groupId>com.codoid.products</groupId>
<artifactId>fillo</artifactId>
<version>1.18</version>
</dependency>

To start using Fillo in the code, create a class file in Eclipse and type the following code in a main method. This code first...

Debugging in Eclipse

During the coding journey, a very useful technique to figure out logic problems is known as debugging. You remove the bugs in the code using debugging. To use the debugger in Eclipse, navigate to the Run | Debug As menu, or simply press F11:

You will get the popup shown previously. Optionally, click on Remember my decision and then click on the Yes button.

The screen that gets displayed is shown as follows:

The box labelled 1 is where the variable and expression values can be checked and the box labelled 2 is the breakpoint on which the execution has halted. Now one can progress line-by-line using F5 or F6. F5 will go into each individual called method, whereas F6 will not. Clicking F8 will continue the execution, which might halt at the next breakpoint, if present.

The topic of debugging can consume an entire mini-book but as far as this book is concerned...

Summary

In this chapter, we had a look at the different locators available for desktop as well as mobile applications. We saw examples of absolute and relative XPaths (customized XPaths) and also how to construct XPaths dynamically. We had a look at the tagName static method and also understood how to find elements with container elements. Next, we had a look at mobile locators and the different tools available to us for automating mobile applications. We understood the different types of mobile applications. Finally, we touched on debugging in the Eclipse IDE. In Chapter 3, Basic Selenium Commands and Their Usage in Building a Framework, we will start looking at writing pieces of code in a linear fashion.

Left arrow icon Right arrow icon
Download code icon Download Code

Key benefits

  • Learn Selenium from the ground up
  • Design your own testing framework
  • Create reusable functionality in your framework

Description

Selenium WebDriver is a platform-independent API for automating the testing of both browser and mobile applications. It is also a core technology in many other browser automation tools, APIs, and frameworks. This book will guide you through the WebDriver APIs that are used in automation tests. Chapter by chapter, we will construct the building blocks of a page object model framework as you learn about the required Java and Selenium methods and terminology. The book starts with an introduction to the same-origin policy, cross-site scripting dangers, and the Document Object Model (DOM). Moving ahead, we'll learn about XPath, which allows us to select items on a page, and how to design a customized XPath. After that, we will be creating singleton patterns and drivers. Then you will learn about synchronization and handling pop-up windows. You will see how to create a factory for browsers and understand command design patterns applicable to this area. At the end of the book, we tie all this together by creating a framework and implementing multi-browser testing with Selenium Grid.

Who is this book for?

This book is for software testers or developers.

What you will learn

  • Understand what an XPath is and how to design a customized XPath
  • Learn how to create a Maven project and build
  • Create a Singleton driver
  • Get to grips with Jenkins integration
  • Create a factory for browsers
  • Implement multi-browser testing with Selenium Grid
  • Create a sample pop-up window and JavaScript alert
  • Report using Extent Reports

Product Details

Country selected
Publication date, Length, Edition, Language, ISBN-13
Publication date : Oct 30, 2018
Length: 192 pages
Edition : 1st
Language : English
ISBN-13 : 9781789611342
Category :

What do you get with eBook?

Product feature icon Instant access to your Digital eBook purchase
Product feature icon Download this book in EPUB and PDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want
OR
Modal Close icon
Payment Processing...
tick Completed

Billing Address

Product Details

Publication date : Oct 30, 2018
Length: 192 pages
Edition : 1st
Language : English
ISBN-13 : 9781789611342
Category :

Packt Subscriptions

See our plans and pricing
Modal Close icon
€18.99 billed monthly
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Simple pricing, no contract
€189.99 billed annually
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just €5 each
Feature tick icon Exclusive print discounts
€264.99 billed in 18 months
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just €5 each
Feature tick icon Exclusive print discounts

Frequently bought together


Stars icon
Total 94.97
Mastering Selenium WebDriver 3.0
€36.99
Selenium WebDriver Quick Start Guide
€24.99
Selenium WebDriver 3 Practical Guide
€32.99
Total 94.97 Stars icon
Banner background image

Table of Contents

9 Chapters
Introducing Selenium WebDriver and Environment Setup Chevron down icon Chevron up icon
Understanding the Document Object Model and Creating Customized XPaths Chevron down icon Chevron up icon
Basic Selenium Commands and Their Usage in Building a Framework Chevron down icon Chevron up icon
Handling Popups, Frames, and Alerts Chevron down icon Chevron up icon
Synchronization Chevron down icon Chevron up icon
The Actions Class and JavascriptExecutor Chevron down icon Chevron up icon
The Command Pattern and Creating Components Chevron down icon Chevron up icon
Hybrid Framework Chevron down icon Chevron up icon
Other Books You May Enjoy Chevron down icon Chevron up icon

Customer reviews

Rating distribution
Full star icon Full star icon Full star icon Full star icon Empty star icon 4
(3 Ratings)
5 star 66.7%
4 star 0%
3 star 0%
2 star 33.3%
1 star 0%
Ramkrishna Bhandare Jan 23, 2019
Full star icon Full star icon Full star icon Full star icon Full star icon 5
value for money
Amazon Verified review Amazon
Ashutosh Rai May 28, 2019
Full star icon Full star icon Full star icon Full star icon Full star icon 5
This book is simple and easy to understand, If you are new in Selenium Automation its a good starting point. If you are already good in Selenium, this book works as a reference book to use the variety of code snippets.
Amazon Verified review Amazon
Abhishek Kar Apr 05, 2019
Full star icon Full star icon Empty star icon Empty star icon Empty star icon 2
Not elaborate enough to understand everything clearly
Amazon Verified review Amazon
Get free access to Packt library with over 7500+ books and video courses for 7 days!
Start Free Trial

FAQs

How do I buy and download an eBook? Chevron down icon Chevron up icon

Where there is an eBook version of a title available, you can buy it from the book details for that title. Add either the standalone eBook or the eBook and print book bundle to your shopping cart. Your eBook will show in your cart as a product on its own. After completing checkout and payment in the normal way, you will receive your receipt on the screen containing a link to a personalised PDF download file. This link will remain active for 30 days. You can download backup copies of the file by logging in to your account at any time.

If you already have Adobe reader installed, then clicking on the link will download and open the PDF file directly. If you don't, then save the PDF file on your machine and download the Reader to view it.

Please Note: Packt eBooks are non-returnable and non-refundable.

Packt eBook and Licensing When you buy an eBook from Packt Publishing, completing your purchase means you accept the terms of our licence agreement. Please read the full text of the agreement. In it we have tried to balance the need for the ebook to be usable for you the reader with our needs to protect the rights of us as Publishers and of our authors. In summary, the agreement says:

  • You may make copies of your eBook for your own use onto any machine
  • You may not pass copies of the eBook on to anyone else
How can I make a purchase on your website? Chevron down icon Chevron up icon

If you want to purchase a video course, eBook or Bundle (Print+eBook) please follow below steps:

  1. Register on our website using your email address and the password.
  2. Search for the title by name or ISBN using the search option.
  3. Select the title you want to purchase.
  4. Choose the format you wish to purchase the title in; if you order the Print Book, you get a free eBook copy of the same title. 
  5. Proceed with the checkout process (payment to be made using Credit Card, Debit Cart, or PayPal)
Where can I access support around an eBook? Chevron down icon Chevron up icon
  • If you experience a problem with using or installing Adobe Reader, the contact Adobe directly.
  • To view the errata for the book, see www.packtpub.com/support and view the pages for the title you have.
  • To view your account details or to download a new copy of the book go to www.packtpub.com/account
  • To contact us directly if a problem is not resolved, use www.packtpub.com/contact-us
What eBook formats do Packt support? Chevron down icon Chevron up icon

Our eBooks are currently available in a variety of formats such as PDF and ePubs. In the future, this may well change with trends and development in technology, but please note that our PDFs are not Adobe eBook Reader format, which has greater restrictions on security.

You will need to use Adobe Reader v9 or later in order to read Packt's PDF eBooks.

What are the benefits of eBooks? Chevron down icon Chevron up icon
  • You can get the information you need immediately
  • You can easily take them with you on a laptop
  • You can download them an unlimited number of times
  • You can print them out
  • They are copy-paste enabled
  • They are searchable
  • There is no password protection
  • They are lower price than print
  • They save resources and space
What is an eBook? Chevron down icon Chevron up icon

Packt eBooks are a complete electronic version of the print edition, available in PDF and ePub formats. Every piece of content down to the page numbering is the same. Because we save the costs of printing and shipping the book to you, we are able to offer eBooks at a lower cost than print editions.

When you have purchased an eBook, simply login to your account and click on the link in Your Download Area. We recommend you saving the file to your hard drive before opening it.

For optimal viewing of our eBooks, we recommend you download and install the free Adobe Reader version 9.