How To Choose Correct Locator In Selenium?

0
41
Spread the love
  • 1
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
    1
    Share

Finding objects or elements in Webpages is the main job while coding with Selenium.You can get Locators from here by which you can uniquely locate your elements in webpage.

This post talk about the priority of choosing the locator. You can think about mandatory and assistive properties to uniquely identify an object in Webpages.

The different locator can be..

  • ID
  • Name
  • Class Name
  • CSS
  • Index
  • Tag Name
  • Link Text
  • Partial Link Text
  • xpath
  • Javascript
  • etc
Here is a pyramid or thumb rule to determine the mandatory properties to select locators that can uniquely determine an element in the webpage.

The thumb rule says:

Try to get id/Name first to identify an object using developer console. If developer has not provided these then go for Secondary locator that is Xpath,CSS,Index etc to identify an object or element uniquely. If you fail to get first 2 then go with Composite locator or assistive locator  to determine an object or element uniquely.
Let me know if you like the post. Please share this if you liked it. Also please feel free to comment.
Don't miss out!
Subscribe To Newsletter

Receive top technical news, lesson ideas, travel tips and more!

Invalid email address
Give it a try. You can unsubscribe at any time.

Spread the love
  • 1
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
    1
    Share

LEAVE A REPLY

Please enter your comment!
Please enter your name here