Find texts that contains quotation marks by xpath in Selenium
问题 I just got an error in Selenium(Java): Unable to locate an element with the xpath expression //*[contains(.,'The field SomeField must be a string or array type with a maximum length of '60'.')] Apparently, there are two ' which broke the expression. So I changed the code from WebElement elem = findElement(By.xpath("//*[contains(.,'" + arg + "')]")); to WebElement elem = findElement(By.xpath("//*[contains(.,'" + arg.toString().replace("'", "\'") + "')]")); WebElement elem = findElement(By