Home » Selenium IDE- Locating Strategies By DOM

Selenium IDE- Locating Strategies By DOM

by Online Tutorials Library

Selenium IDE- Locating Strategies (By DOM)

DOM stands for Document Object Model. In simple words, DOM specifies the structural representation of HTML elements.

There are four ways through which we can identify and locate a web element using DOM.

  1. getElementById
  2. getElementsByName
  3. dom:name (applies only to elements within a named form)
  4. dom:index

1.getElementByID

  • Syntax: document.getElementById(“id of the element”)
  • Id of the element – It is the value of the Id attribute which is beig accessed.
  • For example, we will define the DOM value for the “Username” text box of Test and Quiz login page as: document.getElementById(“email”)

2.getElementsByName

  • Syntax:document.getElementByName(“name”)[index] Name – It is the value of name attribute which is being accessed.
  • Index – An integer value used to specify the location of the desired element.
  • For example, we will define the DOM value for the “Username” text box of Test and Quiz login page as: document.getElementByName(“email_id”)

3.dom:name

  • Syntax : document.forms[“name of the form”].elements[“name of the element”]
  • Name of the form – It is the value of the name attribute of the form tag that contains the element you want to access.
  • Name of the element – It is the value of the name attribute of the element you want to access.
  • Example: “document.forms[“home”].elements[“userName”]”

4.dom:index

  • Syntax : document.forms[index of the form].elements[index of the element]
  • Index of the form – The integer value of the index (starting at 0) of the form with respect to the whole page.
  • Index of the element – The integer value of the index (starting at 0) of the form with respect to the whole form that contains it.

You may also like