5

How can I select a xpath that contains a text with ""

Let say my text on the page is: "my text" (this includes the "").

When I make the xpath I do in VS:

"//td[contains(.,'"mytext">')]"

But VS doesnt see this as correct because it shows mytext in white as if it doesnt belong to the xpath

It says it is a syntax error and it expects an ','.

So how can I make an xpth that uses an contain where the text has an "".

2 Answers 2

4

The answer is pretty simple, escape the double quote characters:

"//td[contains(.,'\"mytext\">')]"

This is a reference of what characters need escaping: https://blogs.msdn.microsoft.com/csharpfaq/2004/03/12/what-character-escape-sequences-are-available/

Hope it helps.

1
  • That reference page seems to be broken. Aug 2, 2019 at 20:35
2

If the context of your XPath is XML, then escape the double quotes with ":

//td[contains(.,'"mytext">')]

See also: Simplified XML Escaping

If the context of your XPat is not XML, you might try

//td[contains(.,concat('"','mytext', '"', '>'))]

to see if VS is happier with that expression, or set a separate variable for " constant, and build up your XPath piecewise from it.

If that doesn't help in your context, see how to escape single quote in xslt substring function

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.