如何在格式化的xpath中使用撇号? [英] How to use apostrophe in formatted xpath?
本文介绍了如何在格式化的xpath中使用撇号?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我将定位器放在属性文件中,如:
I have place the locator in properties file like :
header.navigation.product.link = //div[contains(@class,'grid-')]//li/a[contains(.,'%s')]
当我在我的代码中使用这个定位器时 -
and while I'm using this locator in my code-
String headerproductlink = String.format(ConfigurationManager.getBundle()
.getString("header.navigation.category.link"), category)
和 类别=女性健身房服装
And category = Women's Gym Clothing
当我试图找到它无法找到的元素时。
即使我已经尝试过 Women \的健身服
但没有成功。
While I'm trying to locate the element it unable to find.
even i have tried as Women\'s Gym Clothing
but no success.
有人可以请建议一个方法?
Can someone please suggest a way ?
推荐答案
以下不同方式适合我:
属性文件中的定位符:
another.header=xpath=//h1[contains(.,"%s")]
Java代码:
String t = "st. john\'s bay - women";
String header = String.format(getBundle().getString("another.header"), t);
CommonStep.get("https://www.jcpenney.com/g/st-johns-bay-women/N-bwo3xZ1z0nvauZ1z0nh7w");
String headerText=ElementFactory.$(header).getText();
以下也工作正常
Locator in属性文件:
Locator in Property file:
another.header={'locator':'xpath=//h1[contains(.,"%s")]'}
Java代码:
String t = "st. john\\'s bay - women";
...
或
物业档案中的定位器:
Or Locator in Property file:
another.header={"locator":"xpath=//h1[contains(.,\\"%s\\")]"}
Java代码:
String t = "st. john's bay - women";
...
这篇关于如何在格式化的xpath中使用撇号?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文