XML解析器在机器人框架中不起作用

时间:2017-06-26 19:03:33

标签: xml robotframework

我正在使用xml解析器来访问响应中的元素 这是代码

# define library 
*** Settings ***
Library  SudsLibrary
Library  XML
Library        Collections
*** Variables ***
*** Test Cases ***
test
    abc

*** Keywords ***
    # create soap client object 
    Create Soap Client    http://www.webservicex.com/globalweather.asmx?wsdl
    ${GetCitiesByCountry}    Create Wsdl Object   GetCitiesByCountry
   ${GetCitiesByCountry.CountryName}    Set Variable    india
    # call soap web service 
    call soap method  GetCitiesByCountry  ${GetCitiesByCountry}
    log  ${GetCitiesByCountry}
    ${soap_response}    Get Last Received
    Log    ${soap_response}
    ${root}=   parse xml  ${soap_response}
    log  ${root}
    ${root1}=   parse xml  ${soap_response}  first
    log  ${root1}

这是输出:它不显示生成的xml

Documentation:  
Logs the given message with the given level.
Start / End / Elapsed:  20170626 11:52:46.886 / 20170626 11:52:46.886 / 00:00:00.000
11:52:46.886    INFO    <Element 'Envelope' at 0x0000000003670930
BuiltIn . Log ${root1}
Documentation:  
Logs the given message with the given level.
Start / End / Elapsed:  20170626 11:52:46.887 / 20170626 11:52:46.887 / 00:00:00.000
11:52:46.887    INFO    <Element '{http://schemas.xmlsoap.org/soap/envelope/}Envelope' at 0x0000000003728C60>

1 个答案:

答案 0 :(得分:3)

在网络服务的响应中,有一些奇怪的事情正在发生。似乎它的一部分是HTML编码,而另一部分则不是。无法解释,但通过简单的字符串替换就可以轻松解决。

*** Settings ***
Library   SudsLibrary
Library   XML
Library   String
*** Test Cases ***
Test Webservice
    # create soap client object 
    Create Soap Client    http://www.webservicex.com/globalweather.asmx?wsdl

    ${GetCitiesByCountry}    Create Wsdl Object   GetCitiesByCountry
    ${GetCitiesByCountry.CountryName}    Set Variable    india

    # # call soap web service 
    call soap method  GetCitiesByCountry  ${GetCitiesByCountry}
    ${soap_response}    Get Last Received

    # Clean up response 
    ${soap_response}     Replace String    ${soap_response}    &lt;    <
    ${soap_response}     Replace String    ${soap_response}    &gt;    >    

    ${node}=   Get Element Text    ${soap_response}  .//Table[1]//Country[1]
    Log To Console    ${node}
相关问题