Locators Use in Selenium WebDrive

|
| By Webner

The automation process in selenium can be followed as:

  • Launching Browser
  • Opening the desired website to be automated
  • Locating web elements like textbox
  • Performing operations on the located web elements like writing in the textbox
  • Performing assertions like checking the “Success” message

Using Developer Tool

Locating web elements we need knowledge of their HTML attributes. For the source code of specific elements, we can use an in-built developer tool.

Here are the steps for finding HTML attributes:

  • Lunch a website to be automated e.g. – “https://www.google.co.in/
  • Press F12 to lunch the developer tool
  • Click on the inspect-element icon or we can use the command Ctrl +Shift + C.
  • After clicking on the inspect element icon, click on the web element to be located.
  • We can see the different attributes of the web elements like – Id, Class, and Name, along with its Tag like input, div, etc. Now we can use these tags, attributes, and values to locate elements using different locators.

Locators Use in Selenium WebDrive
There are 8 locators used in the selenium WebDrive

  1. By ID: Locators element using Id attributes in the web element.
  2. By className: Locators element using className in the web element.
  3. By tagName: Locators element using tagName in the web element
  4. By Name: Locators element using name attributes
  5. By linkText: Locators web element of link type using their Text
  6. By partialLinkText: Locators web element of link type with partial matching text.
  7. By cssSelector: Locators web element using CSS its CSS Selector patterns.
  8. By xpath: Locators web element using its XPATH.

Leave a Reply

Your email address will not be published. Required fields are marked *