1

Resolved

Incorrect class XPath

description

The XPath query for FindBy.Class does not correctly handle elements with multiple classes. It should be changed to the following:

string.Format("//*[contains(concat(' ', normalize-space(@class), ' '), ' {0} ')]", locator.Value);

(courtesy http://cweiske.de/tagebuch/XPath%3A%20Select%20element%20by%20class.htm)

comments

anderslyman wrote Apr 12, 2013 at 3:32 PM

Good call and a clever implementation - it took me a minute to realize that the additional spaces are ensuring an exact match of a given class.

wrote Apr 12, 2013 at 3:38 PM

anderslyman wrote Apr 12, 2013 at 5:07 PM

Fixed and pushed latest nuget package.

SamR wrote Apr 17, 2013 at 7:33 AM

This doesn't seem to be working properly - it looks like the line:

string.Format("//*[contains(concat(' ', normalize-space(@class), ' '), {0})]", string.Format(" {0} ", locator.Value));

is missing single quotes around that first format item (ie '{0}' instead of {0})

anderslyman wrote Apr 30, 2013 at 4:35 AM

Sorry for the delay, I was out of town for a while.
I updated in two places and forgot to literalize the XPath in that area.
There is no guarantee that the value the user provides has properly escaped single and double quotes, so it passes through an "XpathLiteral()" function that takes care of that, and also wraps the entire value in single or double quotes (depending on the use case).

Anyhow, I'll fix it and send in an update tomorrow.

anderslyman wrote May 1, 2013 at 3:24 PM

Fixed and pushed latest nuget package.

wrote May 16, 2013 at 8:23 AM

wrote May 16, 2013 at 8:23 AM

wrote Jun 14, 2013 at 7:49 AM