We may not be able to locate the elements directly using their unique attributes as some elements do not have unique attributes (id or name). Some attributes are dynamically changed. There could be elements without attributes. Hence we may have to locate them differently than the static elements.
XPath can be used for:
- Locating elements with respect to a known element
- Locating elements with partially static attribute values
- Locating elements without attributes or without unique attributes
XPath can do bidirectional navigation (Going forward and backward)
XPath is one of most flexible and strongest location strategy and can be used for locating an element in a web page.