Selenium Testing - SPLessons

Selenium Locating Elements

Home > Lesson > Chapter 12
SPLessons 5 Steps, 3 Clicks
5 Steps - 3 Clicks

Selenium Locating Elements

Selenium Locating Elements

shape Introduction

Selenium Locating Elements, To compose UI tests with Selenium WebDriver it should have the capacity to recognize site page components quick and in a precise way. Locators are used to locate GUI Elements. Locators can be located by using NameID,  Xpath, DOMLink TextCSS Selector. Following are the methods .

ID

shape Description

By using the ID, elements can be located. There are two different steps to found the elements by ID

shape Step 1

Drive to this URL Open Facebook

shape Step 2

Selenium Locating Elements will Use firebug to inspect the Username. Inspection of any web site is simple in any web site, for example while entering any credentials to the form, by giving right click on the text field user can change the name of the filed and also at the place of password one can keep the show or text to visible the data.

shape Step 3

Selenium Locating Elements, Open the selenium IDE and in command tab, type id=email, the location will  be located that has been shown in the image with red color marked.

Name

shape Description

Elements can be found by giving the Names. By following the steps, elements can be located by Names. Name type is used to locate prime element with similar name , in case variuos elements have similar values for a particular name, then it's better utilize filters to future refining purpose.

shape Step 1

Drive to this URL and select Username in the window. Open Facebook

shape Step 2

Type name=email in Target window then same element will be displayed under the name of target as shown in the image.

X path

shape Description

Selenium Locating Elements, The XPath is nothing but a dialect that utilized for XML document to locate the nodes, one can use the XPath when thers is no id or name element to locate, these locators can be used to declare elements via using attributes.

shape Step 1

Select the Tab, and open it with firebug, Height and Width of the tab will appear.

shape Step 2

Copy the Xpath of that Tab and place it in command with Two Slashes.

DOM

shape Description

DOM stands for Document Object Model. Page elements can be accessed by using Document Object Model. It represents the static page and it will be drived by using JavaScript code that access an element. There are two steps to find  page elements using Document Object Model.

shape Step 1

Drive to this URL, select keep me logged in Checkbox with firebug.

shape Step 2

Enter the document.getElementById("persist_box") and press find, checkbox will be highlighted.

shape Description

By using Links, elements  can founded. locating hyperlinks by link text, by using this strategy the main component with the link text value coordinating the area will be returned. On the off chance that no component has a coordinating connection content trait, a NoSuchElementException will be raised. . The following steps will describe how the links can used in this topic.

shape Step 1

Drive to this URL and select contact and open it with firebug.  

shape Step 2

In Target window, type link=contact and press Find button output, contact will be highlighted.

CSS

shape Description

CSS stands for Cascading Style Sheets which are define rules how the elements should appear on the web pages. CSS Styles are very expressive and allows user to have the high degree of control over the styling of the HTML Elements with a little bit of code. HTML and CSS are evolved on several years back and now the latest version is the CSS3 which have the lot of new capabilities to existing once. CSS3 and HTML5 together known as the forefront of the advanced webdesign and web development. Previously ID is used to locate the elements, in the same manner, locating the ID by using CSS. Below two steps will describe how CSS is used to find the elements.

shape Step 1

Drive to this URL and select Email and open it with firebug.

shape Step 2

Type CSS=input#email in Target and press Find, then the Email box will be highlighted.  CSS are used to handle the designing (looking) part of the web page which can handle the color of the text, font style, spacing between the paragraphs, background images, colors, layout designs, variations in displays for different devices and as well as other effects. User can learn the CSS easily which provides powerful control over the HTML document mostly CSS are combined with the markup languages like HTML or XHTML.

Summary

shape Key Points

  • Each Locator will perform specified Operation.
  • Discovering Address is some what difficult in Xpath.
  • Selenium grid is the strategy to distribute the test through the various servers.
  • X-Path is used to find the web element in web application and also to recognize dynamic elements.