Tony
Tony

Reputation: 407

Using an apostrophe in an xpath expression

I have some html like this:

<a>This is the Children's Miracle Network</a>

I as expected am getting an error when I do

 WebElement ele = driver.findElement(By.xpath("//a[contains(text(),'This is the Children's Miracle Network)]"));

because the apostrophe in Children's is unquoting the text. I tried using double ' (like '') and backslashing (\') but that did not work. I am not sure what to do? Any suggestions?

Upvotes: 0

Views: 97

Answers (1)

wero
wero

Reputation: 32980

You can try

WebElement ele = driver.findElement(By.xpath("//a[contains(text(),\"This is the Children's Miracle Network\")]"));

Upvotes: 1

Related Questions