我有一些像这样的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 中的撇号是取消对文本的引用。我尝试使用双'(如'')和反斜杠(\'),但这不起作用。我不知道该怎么办?有什么建议吗?
最佳答案
你可以试试
WebElement ele = driver.findElement(By.xpath("//a[contains(text(),\"This is the Children's Miracle Network\")]"));
关于java - 在 xpath 表达式中使用撇号,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33025742/