Appium xpath 转义撇号 [英] Appium xpath escaping apostrophes

查看:24
本文介绍了Appium xpath 转义撇号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的 appium 脚本中有以下代码:

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']"));
    }

测试挂起,因为它将don't"中的撇号视为结束@name 值的最后一个撇号.我曾尝试使用 \', \', '

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?

推荐答案

AFAIK,你不能在 xpath 中转义引号,但你可以在 Java 中转义引号.所以尝试对 xpath 文字字符串分隔符使用转义双引号,例如:

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

这篇关于Appium xpath 转义撇号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆