Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use apostrophe (') in xpath while finding element using webdriver?

Tags:

I need to use apostrophe (') in my xpath expression which i need to use in finding elements using webdriver

i need to use below Xpath expression

//input[@text="WE'd like to hear from you"]

while using the above expression in find elements function i am replacing double quotes with single quotes

driver.findelements(By.xpath("//input[@text='WE'd like to hear from you']"))
like image 307
dolittle Avatar asked May 31 '16 10:05

dolittle


2 Answers

Use the xpath as shown below:

driver.findElements(By.xpath("//input[contains(@text,\"WE'd\")]"));

Hope this helps.

like image 122
k.s. Karthik Avatar answered Sep 24 '22 10:09

k.s. Karthik


You have to use double-quotes as your XPath string literal delimiter, since XPath 1.0 doesn't provide a way of escaping quotes. In addition to that, you can escape the double-quotes in Java, to avoid it from conflicting with your Java string delimiter, which also use double-quotes :

driver.findelements(By.xpath("//input[@text=\"WE'd like to hear from you\"]"))
like image 44
har07 Avatar answered Sep 24 '22 10:09

har07