2

I have the code below in my appium script:

    public boolean isErrorDisplayedUnrecognisedLoginCredentials() {
        return appDriver.isElementExist(By.xpath("//UIAStaticText[@name='We don't recognize this user ID or password']"));
    }

The test is hanging since it treats the apostrophe in "don't" as a final apostrophe to close off the @name value. I have tried escaping the apostrophe in "don't" by using \', \', '

However, none of these are working and the tests keep failing. Anyone know how to get round this?

Charlie S
  • 4,366
  • 6
  • 59
  • 97

2 Answers2

4

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\"]")
har07
  • 88,338
  • 12
  • 84
  • 137
  • 1
    You can escape quotes and apostrophes in XPath 2.0 by doubling them, but there is no way of doing it in XPath 1.0. – Michael Kay Jun 11 '15 at 11:49
0

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"]")