Appium xpath escaping apostrophes Appium xpath escaping apostrophes selenium selenium

Appium xpath escaping apostrophes


AFAIK, you can't escape quotes in xpath, but you can escape quotes in Java. So try to use escaped double quotes for the xpath literal string delimiter, for example :

By.xpath("//UIAStaticText[@name=\"We don't recognize this user ID or password\"]")


With XPath 1.0 (It should work with XPath 2.0):

By.xpath("//UIAStaticText[@name='We don't recognize this user ID or password']")

With XPath 2.0 we have two solutions:

  1. By doubling the single apostrophe you will be able to escape the apostrophe:By.xpath("//UIAStaticText[@name='We don''t recognize this user ID or password']")

Recommended solution:

  1. To define the Xpath, I would use the double quote (") instead of a apostrophe:By.xpath("//UIAStaticText[@name="We don't recognize this user ID or password"]")