For Example:
By.xpath("//*[@id="ext-gen1035"]/div/div[3]/i")
There is no way to escape characters at the XPath level, so you can't have a literal XPath string containing both kinds of quote.
If I recall correctly, you can use either single or double quotes to surround a string in XPath.
XPath's string literals can't contain both types of quotes; you need to construct the string using the XPath concat function. For example, if you wanted to match the string "That's mine", he said. , you would need to do something like: text()=concat('"That', "'", 's mine", he said.
The only reliable way of using XPath in Selenium WebDriver for text with apostrophes (single quotes) is to use double quotes for the expression of the XPath.
You can actually use single quotes too:
By.xpath("//*[@id='ext-gen1035']/div/div[3]/i")
Or escape double quotes with a backslash:
By.xpath("//*[@id=\"ext-gen1035\"]/div/div[3]/i")
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