Pad*_*thy 16 java selenium xpath
我需要在我的xpath表达式中使用撇号('),我需要在使用webdriver查找元素时使用它
我需要在Xpath表达式下使用
//input[@text="WE'd like to hear from you"]
Run Code Online (Sandbox Code Playgroud)
在find元素函数中使用上面的表达式时,我用单引号替换双引号
driver.findelements(By.xpath("//input[@text='WE'd like to hear from you']"))
Run Code Online (Sandbox Code Playgroud)
小智 23
使用xpath,如下所示:
driver.findElements(By.xpath("//input[contains(@text,\"WE'd\")]"));
Run Code Online (Sandbox Code Playgroud)
希望这可以帮助.
您必须使用双引号作为XPath字符串文字定界符,因为XPath 1.0并未提供转义引号的方法。除此之外,您还可以在Java中转义双引号,以避免它与Java字符串定界符(也使用双引号)冲突:
driver.findelements(By.xpath("//input[@text=\"WE'd like to hear from you\"]"))
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
16363 次 |
| 最近记录: |