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 "".
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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With