Mastering in XPath for Selenium Test Automation

Introduction

Selenium test automation engineers must be comfortable in locating elements in web pages effectively. XPath are very powerful location strategies used in Selenium as compared to other location strategies (id, name, linkText, partialLinkText and tagName )

Mastering XPath is essential for the Selenium test automation engineers to locate dynamic web elements and elements without id or name. Tagname is not a useful location strategy to locate elements as there are many elements with the same tagname. LinkText is only useful for the <a> tags only. Also, it is not useful when the visible text changes as in multilingual systems.

It is noted that most of the amateur Selenium automation engineers do not pay much attention to master location strategies. Recording and playback will not work with the applications with dynamic content. This leads to failure of test automation scripts (brittle) when web pages with dynamic contents are automated. Most of the testers rely on extracting the XPaths from browser plugins. These tools have got limitations and do not provide best values for dynamic elements. We will discuss XPath in detail with examples and explore few tools to extract XPaths automatically.