【问题标题】:Using an apostrophe in an xpath expression在 xpath 表达式中使用撇号
【发布时间】:2016-01-06 15:54:52
【问题描述】:

我有一些这样的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)]"));

因为 Children's 中的撇号取消了对文本的引用。我尝试使用双'(如'')和反斜杠(\'),但这不起作用。我不知道该怎么办?有什么建议吗?

【问题讨论】:

标签: java xpath escaping


【解决方案1】:

你可以试试

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

【讨论】:

  • 我必须使用双反斜杠吗?
  • 没有任何效果。我最终在 ' 上拆分并使用 contains(text(),'firstpart') 和 contains(text(),'secondpart')]。实际上,我在 ' 上拆分并计算字段并为每个字段创建一个 contains(text()) 。可能不仅仅是“儿童父母的奇迹网络的主要慈善机构”
猜你喜欢
  • 2013-11-20
  • 1970-01-01
  • 2021-10-15
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-07-13
相关资源
最近更新 更多