It is always advisable to use custom Xpath because more often than not they will always identify the element uniquely. For rest of locator strategies, you need to make sure that their occurrence is not more than once in the page. Are you aware of any other Add-on or Plugin which can be used to ease our day to day activities? The above tag has no attribute, so with selenium we can not identify this uniquely. XPath is used everywhere where there is XML.

Uploader: Mezijind
Date Added: 14 September 2008
File Size: 19.24 Mb
Operating Systems: Windows NT/2000/XP/2003/2003/7/8/10 MacOS 10/X
Downloads: 44272
Price: Free* [*Free Regsitration Required]

There is no such thing as reliable locator in Selenium as for choosing locator totally depends on how your application is developed and what all webdrivre is used by the developer for each web element.

How to Locate Web Elements in WebDriver

Selenium provides the following methods to locate elements in a page: Locating Elements by Tag Name 4. The link in the above example has an id that we can use: Use locatod Plugin and Speed Up your automation code writing.

These are the locators locatorr can be used in Selenium. Locating Elements by Class Name 4. By class attribute This locates elements by the value of the class attribute. By finding a nearby element with an id or name attribute ideally a parent element you can locate your target element based on the relationship.


The link in the above example has an id that we can use:. Developer ID is another locator strategy that can be used to identify objects in application. This method is normally the preferred locator for links on a page.

locatog What is CSS location strategy in Selenium? This method locates elements by the exact text it displays. So you may see ID as txt one time and txt the next time. Sumasri is a Sr.

Currently, there fog two filter types:. Since there are often many repeating uses of most tags, it is not often possible to use this method to locate a single element.

The class attribute is used for styling pages, and so chances are that many elements are likely to have the same class. By name Locates elements by the value of their name attribute. ID — Matches by id characteristic. With this strategy, the first element with the matching CSS selector elemetn be returned.

Locators in Selenium WebDriver | Selenium Tutorial

XPath locators are the most complex selector to use. What is the most reliable locator in Selenium WebDriver? Locators for Selenium From my experience I would prioritize them as below: With this strategy, the first element with the name attribute value matching the location will be returned. On a typical login page, you have input fields which could webdrievr like: Eement most reliable locator in Selenium is the one that works for you every single time. Free for 60 days.


Ask New Question Sign In.

It is very helpful when we webdrivfr to extract the content within a Tag. If you have flexible developers or even an eye for the app source code you can always try and get extra IDs added into the code by buying them a beer on Friday evening, taking their sister on a date or just plain begging.

One of the most important skills of a test automation engineer working with Selenium WebDriver is to be able to use appropriate methods to locate elements on a page. This makes the techniques necessary to do so incredibly important. However, the good news is that there is a difference between a good and poorly written locator.