0

How to find the xpath when we have single inverted comma in our html like this-

<td class="ng-binding" sortable="'name'" data-title="'Department Name'" data-title-text="Department Name">dept1</td>

I wanted to find the xpath on the basis of class and sortable as mentioned above.

Code which I've tried-

//td[@class='ng-binding'][@sortable=''name''] 

but it's giving me error.

Any valuable assistance. Please let me know in case of any clarification.

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
PySaad
  • 1,052
  • 16
  • 26
  • What is the error you are seeing? – undetected Selenium Aug 31 '17 at 13:26
  • you could always use contains, but I would say one of the answers providing the precise value is the correct one. `//[contains(@sortable, 'name')]` – mrfreester Aug 31 '17 at 14:57
  • @Saad Try my answer and get back to me if it works or doesn't work. – IamBatman Aug 31 '17 at 15:16
  • 1
    Possible duplicate of [In Java, should I escape a single quotation mark (') in String (double quoted)?](https://stackoverflow.com/questions/16664090/in-java-should-i-escape-a-single-quotation-mark-in-string-double-quoted) – JeffC Aug 31 '17 at 16:03

3 Answers3

0

Try //td[@class='ng-binding'][@sortable="'name'"]

The problem is that by using 2 consecutive single quotes, it's interpreted as if you are passing in an empty string, and then you got name'' after it before closing the tag, which is just plain invalid.

Or escape like :

"//td[@class='ng-binding'][@sortable='\'name\'']"
CounterFlame
  • 1,612
  • 21
  • 31
0

Try :-

"//td[@name='\'name'\'"

OR

"//td[@name=\"'name\'"

refer :- https://sqa.stackexchange.com/questions/26341/how-to-write-xpath-if-i-have-apostrophe-in-my-xpath-element

Hope it will help you :)

Shubham Jain
  • 16,610
  • 15
  • 78
  • 125
0

This locates the element, now if there are more than "1" that match these conditions, it will fail. So adding an index "may" be necessary. Or you need to use different conditions.

//td[@class='ng-binding'][contains(@sortable, 'name')][text()='dept1']
IamBatman
  • 975
  • 12
  • 18