-2

I'm not able to find the xpath for the text from the below xml. I need to get the text, "ABCD" for the analysisId.

<ns1:Results>
<ns1:Type>string</ns1:Type>
<ns1:Key>resolution</ns1:Key>
<ns1:SimpleValue><![CDATA[<ResultAnalysisList priority="0000" analysisId="ABCD" displayName=" ">
<Group id=""
|
|
</ns1:Results>

Any help would be appreciated.

Dikesh Gandhi
  • 447
  • 13
  • 22
Ajay
  • 167
  • 4
  • 15

2 Answers2

0

This can't be done using pure XPath v1.0 (version that selenium supports, if I remember correctly).

Text inside CDATA is not parsed. It is treated as plain text. So in XPath processor's point of view, there is no elements or attributes that you can access using XPath within CDATA.

Related: Xpath to the tag inside CDATA


If CDATA section contains well-formed XML, you could try to get the whole CDATA content using XPath first, and then pass it as a separate XML to your XPath processor (2 steps parsing).

Just FYI, XPath 3.0 has parse-xml() function which can be used for this purpose, something along this line :

//ns1:SimpleValue/parse-xml(.)/ResultAnalysisList/@analysisId

xpath 3.0 demo: http://xpatheval.apphb.com/y6Ln4drA4

Community
  • 1
  • 1
har07
  • 88,338
  • 12
  • 84
  • 137
0

Dirty hack:

substring-before(substring-after(//ns1:SimpleValue,'analysisId="'),'"')
Kim Homann
  • 3,042
  • 1
  • 17
  • 20