68. XPath Optimization






There may be cases where simple changes are made to the application and our previously identified XPath Statements wont work after those simple changes are made to the application. In order to avoid these kind of problems, we've to optimize our XPath Statements before using them in our Selenium Automation.

So that Advantages of Optimizing the XPath Statements are to get the shortest and least breakable XPath Statements.

We've to follow the below four strategies in order to make the XPath Optimized:
  1. Use the id attribute if available but not used
  2. Use the combination of attributes to make the XPath more specific
  3. If there is really nothing to distinguish find the first unique element from its siblings and add the index value to it.
  4. Use the Relative XPath instead of Absolute XPath Statements
Lets implement all the above four strategies that are required to make our XPath Optimized in the upcoming posts.

To start with, lets implement the first strategy to optimize the XPath Statements in next post.

Please comment below to feedback or ask questions.

XPath Optimization Strategy One - Use the id attribute if available for the element but not used in XPath Statements will be explained in the next post.



Followers

Labels