在xpath表达式中使用撇号

时间:2015-10-08 20:52:36

标签: java xpath escaping

我有一些像这样的HTML:

<a>This is the Children's Miracle Network</a>

我按照预期在发生错误时发现错误

 WebElement ele = driver.findElement(By.xpath("//a[contains(text(),'This is the Children's Miracle Network)]"));

因为儿童的撇号是不引用文本的。我试过用双&#39; (比如&#39;&#39;)和反斜杠(\&#39;)但这不起作用。我不知道该怎么办?有什么建议吗?

1 个答案:

答案 0 :(得分:1)

你可以尝试

WebElement ele = driver.findElement(By.xpath("//a[contains(text(),\"This is the Children's Miracle Network\")]"));