Chapter 2. Finding Elements

In this chapter, we will see how to use Selenium WebDriver API to find elements on a Web page and interact with these elements. We will explore various locator strategies supported by Selenium WebDriver. You will learn about:

  • Using browser tools for inspecting elements and page DOM
  • Finding an element using the findElement method
  • Finding elements using the findElements method
  • Finding links
  • Finding elements by tag name
  • Finding elements using CSS selectors
  • Finding elements using XPath
  • Finding elements using tag text contents
  • Finding elements using advanced CSS selectors
  • Using jQuery selectors

Introduction

Web applications, and the web pages within these applications, are commonly written in a mix of Hyper Text Markup Language (HTML), Cascading Style Sheets (CSS), and JavaScript code. Based on user actions like navigating to a website Uniform Resource Locator (URL) or clicking the submit button, a browser sends a request to a web server. Web server processes this request and sends back a response with HTML and related resources, such as JavaScript, CSS, Images, and so on, back to the Browser. The information received from a server is used by the browser to render a web page with various visual elements, such as textboxes, buttons, labels, tables, forms, checkboxes, radio boxes, lists, images, and so on, on the page. While doing so, the browser hides the HTML code and related resources from the user. The user is presented with a graphical user interface in the browser window.

When we want to automate browser interaction using Selenium, we need to tell Selenium how to find a particular element or set of elements on a web page programmatically and simulate user actions on these elements. Selenium provides various selector or locator methods to find elements based on the attribute/value criteria or selector value that we supply in the script.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.12.76.164