How XPath Works in WebDriver

Differences between the XPath engines used by the Selenium 2 drivers.

This documentation previously located on the wiki

At a high level, WebDriver uses a browser’s native XPath capabilities wherever possible. On those browsers that don’t have native XPath support, we have provided our own implementation. This can lead to some unexpected behaviour unless you are aware of the differences in the various xpath engines.

DriverTag and Attribute NamesAttribute ValuesNative XPath Support
HtmlUnitDriverLower-casedAs they appear in the HTMLYes
InternetExplorerDriverLower-casedAs they appear in the HTMLNo
FirefoxDriverCase insensitiveAs they appear in the HTMLYes

This is a little abstract, so for the following piece of HTML:

<input type="text" name="example" />
<INPUT type="text" name="other" />

The following will happen:

XPath expressionHtmlUnitDriverFirefoxDriverInternetExplorerDriver
//input1 (“example”)22
//INPUT020

Matching Implicit Attributes

Sometimes HTML elements do not need attributes to be explicitly declared because they will default to known values. For example, the “input” tag does not require the “type” attribute because it defaults to “text”. The rule of thumb when using xpath in WebDriver is that you should not expect to be able to match against these implicit attributes.