Appium xpath escaping apostrophes

2019-01-20 19:06发布

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?

1条回答
欢心
2楼-- · 2019-01-20 19:43

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\"]")
查看更多
登录 后发表回答