0

I have the following text and i need to write x path

Please upload this owner's ID:

Here when i write x path with text or contains text it doesn't return the matches.

//*[@text()='Please upload this owner's ID:']

I doubt that there is an ' symbol in the word owner's and hence its not giving proper result.

Hope i can find a solution here

Andersson
  • 47,234
  • 13
  • 52
  • 101
Arun Chettur
  • 43
  • 10

2 Answers2

2

try with double quotes.

 //*[@text()="Please upload this owner's ID:"]

or with escape

 //*[@text()='Please upload this owner\'s ID:']
Murthi
  • 5,051
  • 1
  • 8
  • 15
1

Although the escape sequence for a single quote (') in Xml is ', there's a limitation in XPath 1.0 preventing ' from being used directly in a path.

Also, as it stands, your question asks for any element with a text attribute containing the search string, e.g.

 <node text="Please upload this owner's ID:" />

Assuming there are no other text attributes with strings containing those two phases, a hacky approximation to the search would be:

//*[contains(@text, 'Please upload this owner') and contains(@text, 's ID:')]

If however you meant that the element's text() content needed to match (i.e. not a text attribute):

 <node>Please upload this owner's ID</node>

Then the same hack would be:

//*[contains(text(), 'Please upload this owner') and contains(text(), 's ID:')]
StuartLC
  • 96,413
  • 17
  • 181
  • 256
  • I think you might have stumbled [upon this limitation in XPath 1.0](https://stackoverflow.com/q/13482352/314291) – StuartLC May 29 '18 at 09:20
  • thank you stuart it worked. your 3rd condition worked. – Arun Chettur May 29 '18 at 16:22
  • Just one doubt . In general can we not use @text? in some cases when i give @text()='ABC' it gives results.' – Arun Chettur May 29 '18 at 16:23
  • `@xxx` means find the [value of attribute](https://stackoverflow.com/a/103417/314291) `xxx`, whereas `text()` means get the text value(s) under the current node. Have a look at my xml / html sample data (``) to see the difference. `@text()` shouldn't be valid IMO. – StuartLC May 29 '18 at 16:35