简体   繁体   English

如何在字符串中使用引号“或”字符?

[英]How can I use a quote " or ' character within a string?

am working on selenium webdriver using JAVA ! 我正在使用JAVA开发Selenium Webdriver!

am trying to pass a string dynamically using the variable exp 我正在尝试使用变量exp动态传递字符串

String exp=",,,4'-TETRA; P-CHLORIDE";

d.findElement(By.xpath("a[contains(text(),\""+exp+"\")]//ancestor::table//parent::div")).sendKeys(Keys.ARROW_DOWN);

but its giving me an error : 但它给我一个错误:

Unable to locate element: {"method":"xpath","selector":

"a[contains(text(),\",,,4'-TETRA; P-CHLORIDE\")]//ancestor::table//parent::div"

}

Use '"+exp+"' instead of \\""+exp+"\\" : 使用'"+exp+"'代替\\""+exp+"\\"

  d.findElement(By.xpath("a[contains(text(),'"+exp+"')]//ancestor::table//parent::div")).sendKeys(Keys.ARROW_DOWN);

Update 更新资料

d.findElement(By.xpath('a[contains(text(),"'+exp+'")]//ancestor::table//parent::div')).sendKeys(Keys.ARROW_DOWN);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM