【发布时间】:2022-01-03 18:36:31
【问题描述】:
我在修改同一个 XML 中具有相同 Xpath 的多个元素时遇到问题。代码如下:
*** Settings ***
Library XML
Library String
*** Variables ***
${XMLpath} AbsolutePath.xml
${Xpath} GM/BODY/CMss/message #(there are two elements with this xpath)
*** Test Cases ***
TestCase
${root} Parse Xml ${XMLpath}
@{CMmessage} Get Elements Text ${root} ${Xpath}
${CMmessage1} Set Variable @{CMmessage}[1]
#...CMmessage1 modifications...
Set ${root} ${CMmessage1} \ ${Xpath} #Here is failing due there are multiple elements (2) matching the XPath
${CMmessage2} Set Variable @{CMmessage}[2]
#...CMmessage2 modfications...
Set ${root} ${CMmessage1} \ ${Xpath} #Here is failing due there are multiple elements (2) matching the XPath
Save Xml ${root} ${XMLpath}
有问题,Xpath给出的不是唯一的。我试过索引:
Set ${root} ${CMmessage1} \ ${Xpath}[1]
Set ${root} ${CMmessage1} \ ${Xpath}[2]
但这没用...有人知道如何处理 Robotframework-XMLlibrary 中的索引吗?
【问题讨论】:
标签: xml xpath robotframework