When the webpage has text test'"message { both single & double quotes in it}. I have to find it using Xpath
As many said, in forums I looked in for the right approaches, tried using '' as escape character. But it didn't work, as expected!
Hence my attempts & errors are below & How do I achieve the expected result ?
the escape character didn't help in locating the element within browser DOM Still I tried in script, to see any miracle happens, But just the errors.
- Attempt with 'single escape character'
d.FindElement(By.XPath("//div[text()=\"test\"message\"]"));
Error: Unable to locate an element with the xpath expression //div[text()="test"message"] because of the following error: SyntaxError: Failed to execute 'evaluate' on 'Document': The string '//div[text()="test"message"]' is not a valid XPath expression.
- Attempt with 'double escape character' as the scripting language is c#
d.FindElement(By.XPath("//div[text()=\"test\\\"message\"]"));
Error: Unable to locate an element with the xpath expression //div[text()="test\"message"]
because of the following error:
SyntaxError: Failed to execute 'evaluate' on 'Document': The string //div[text()="test\"message"]
is not a valid XPath expression.