Certified Selenium Professiona Learning Resources Locating by DOM

Learning Resources
 

Locating by DOM

The Document Object Model represents an HTML document and can be accessed using JavaScript. This location strategy takes JavaScript that evaluates to an element on the page, which can be simply the element’s location using the hierarchical dotted notation.

Since only dom locators start with “document”, it is not necessary to include the dom= label when specifying a DOM locator.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
 
  
    id="loginForm">
     name="username" type="text" />
     name="password" type="password" />
     name="continue" type="submit" value="Login" />
     name="continue" type="button" value="Clear" />
   
 
 
  • dom=document.getElementById('loginForm') (3)
  • dom=document.forms['loginForm'] (3)
  • dom=document.forms[0] (3)
  • document.forms[0].username (4)
  • document.forms[0].elements['username'] (4)
  • document.forms[0].elements[0] (4)
  • document.forms[0].elements[3] (7)
 For Support