How to Create Xpath Using Linq

Published: Sun May 10 2015

As an alternative to my previous xpath library, XpathItUp, I've created a lambda based framework (LambdaToXpath) for generating xpath expressions. The goal is to improve and address some of the short comings of my previous library.

The primary use case for the library is generating xpath expressions for automated testing (e.g. Selenium Web Tests), but LambdaToXpath doesn't depend on any third party libraries, and can be used to generate generic xpath expressions.

The most obvious difference from XpathItUp is that LambdaToXpath let's you describe xpath expressions through C# lambda expressions rather than a fluent method chain. Another difference is that the generated expressions are centered around a specified target element, which offers more granular control in cases where you need a specific node to be returned. One example of this is selecting elements to click in web tests.