1.

Which locator you used and why?

Answer»

There are 8 types of locators in selenium WebDriver.It is very important to decide on which locator we should use.

To find web element Selenium web driver takes time which is more or less BASED on the type of locator we used. Test execution time will increase if we use a slow locator. So the selection of locator should be correct and FASTER. When we use the ID locator, Page Object Model (POM) has advantages. ID helps in identifying web element uniquely.

If a unique ID is not available, we use Name locator. Name locator may not identify a web element uniquely as a web page as multiple web elements can share the same name. We can request developers to provide a unique ID or Name for every web element to faster test script execution.

To locate a list of web elements, we use ClassName or TagName. LinkText or PartialLinkText can be used for ANCHOR tag web elements.

When web element has not Unique ID and name, CSS Selector is the best option to use. It is faster and also it improves the performance, and very compatible across browsers. CSS engine is consistent in all browsers and very useful to test applications on multiple browsers. XPath does not work in IE always so CSS is best for IE.

XPath is the last option to use as a locator as it is SLOWER among all locators, but it provides reliable ways to locate web elements. XPath engines are different in each browser and make them inconsistent across browsers.



Discussion

No Comment Found