如何在Xpath表达式中使用实例索引?

时间:2019-07-16 23:03:54

标签: karate

我正在尝试使用带有实例计数的简单xPath表达式设置xml值。

我的XML:

 <ebm:ProcessCustomerPaymentBasketTotal>
<ebm:header>
  <ebm:creationDateTime>2019-07-16T05:20:11.446+01:00</ebm:creationDateTime>
  <ebm:serviceID>19da587a352911e985ddb2f6c8a3ba75</ebm:serviceID>
  <ebm:messageID>PPR SERVICE TEST 2019-07-16T23:25:03</ebm:messageID>
  <ebm:languageCode>EN</ebm:languageCode>
  <ebm:versionID>2.0.0</ebm:versionID>
   </ebm:header>
  <ebm:header>
  <ebm:creationDateTime>2019-07-16T05:20:11.461+01:00</ebm:creationDateTime>
  <ebm:serviceID>a38d367635f811e9b9b59ddfef421b03</ebm:serviceID>
  <ebm:messageID>PPR SERVICE TEST</ebm:messageID>
  <ebm:languageCode>EN</ebm:languageCode>
  <ebm:versionID>2.0.0</ebm:versionID>
 </ebm:header>
  </ebm:ProcessCustomerPaymentBasketTotal>

功能文件:(我尝试过的组合)

* set xmlMessage //messageID[2] = '123456' 
* set xmlMessage (//messageID)[2] = '123456'

以上两种组合均无效,无法实现我的目的。您能建议任何解决方法吗?

1 个答案:

答案 0 :(得分:1)

您的xpath错误:

* set xmlMessage //header[2]/messageID = '123456'