1

Given the following SOAP XML response:

http://pastebin.com/f57T8ctD (too large to display in here)

If I try to retrieve the nodes <ssr> with the next Xpath sentence:

//*[name() = 'ssr'][1]

What I am getting is the next:

<ssr xmlns="http://xml.amadeus.com/PNRACC_14_1_1A">
  <type>CTCE</type>
  <status>HK</status>
  <quantity>1</quantity>
  <companyId>OU</companyId>
  <freeText>XXX//GMAIL.COM</freeText>
</ssr>
<ssr xmlns="http://xml.amadeus.com/PNRACC_14_1_1A">
  <type>CTCM</type>
  <status>HK</status>
  <quantity>1</quantity>
  <companyId>OU</companyId>
  <freeText>XXX/SI</freeText>
</ssr>

Instead of only the first one as I have tried to select with the query.

Is there another way to select the different <ssr> nodes specifying the node number?

Mr Lister
  • 45,515
  • 15
  • 108
  • 150
arkanos
  • 95
  • 1
  • 12
  • Sorry, I forgot to add that I also have tried to use //*[local-name() = 'ssr'] without success. – arkanos Dec 10 '15 at 13:48
  • Possible duplicate of [How to select specified node within Xpath node sets by index with Selenium?](http://stackoverflow.com/questions/3674569/how-to-select-specified-node-within-xpath-node-sets-by-index-with-selenium) – har07 Dec 10 '15 at 13:53
  • You really should not use `name()` or `local-name()` for that. Declare the namespaces properly and use namespace prefixes, it's not that hard. – Tomalak Dec 10 '15 at 13:53
  • Hi Tomalak, I have already used that without any success. I use them in the proper way always if I can, but don't know why they did not work this time with this reply. Regarding the duplicate, sorry. I couldn't manage to find the answer as I did not know how to exactly describe my problem. – arkanos Dec 10 '15 at 14:01

1 Answers1

2

Use brackets wrapping the entire XPath except the index :

(//*[name() = 'ssr'])[1]

See the following post for explanation : How to select specified node within Xpath node sets by index with Selenium?

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