Selenium WebDriver Quick Start Guide
上QQ阅读APP看书,第一时间看更新

The two types of XPaths

Let's now understand what absolute XPaths are and how they differ from relative (customized) XPaths:

  • An absolute XPath is the entire path of the WebElement taken from the root node. For example, html/body/div/a.
  • A relative or customized XPath is one in which we use the following format. For example, if the div has an id of ABC, then the same absolute XPath will be //div[@id='ABC']/a.

There is an apparent problem with the absolute type of XPath. If the DOM structure changes in the future (for example, if div is removed), then this path will undergo changes.