Book Image

Learning Selenium Testing Tools - Third Edition

Book Image

Learning Selenium Testing Tools - Third Edition

Overview of this book

Table of Contents (22 chapters)
Learning Selenium Testing Tools Third Edition
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Finding elements


When working with WebDriver on a web application, we will need to find elements on the page. This is the core to being able to work. All the methods to perform actions on the web application (such as typing and clicking) require searching the element first.

Finding an element on the page by its ID

The first item that we will look at is finding an element by ID. Finding elements by ID is one of the easiest ways to do this. We will start with findElementByID(). This method is a helper method that sets an argument for a more generic findElement call. We will see now how we can use it in action. The method's signature looks like the following code:

  findElementById(String using);

The using variable takes the ID of the element that you wish to look for. It will return a WebElement object that we can then work with.

Using findElementById()

We will find an element on the page using the findElementById() method that is on each of the browser driver classes. The findElement calls will...