Skip to content
Advertisement

Convert ReadyAPI xpath for use in Python 3

I’m having trouble converting xpath expressions that I use in ReadyAPI for use in Python 3 with the lxml library. I’ve read the lxml documentation but I’m not getting the same results.

Here’s my XML:

JavaScript

I use the following xpath expressions in ReadyAPI:

//*:Reply[*:Name="Name of Reply"]/*:ID

the expected returned result is:

ID of Reply 1

and:

//*:Reply[*:Name="Name of Reply"]/*:ContentsofReply/*:Content/*:IDofContent

the expected returned result is:

ID of Content 1

How do I get the same results in Python 3 with the lxml library? Thanks in advance.

Advertisement

Answer

The xpath expressions in your questions contain *:prefixes intended to be used with namespaces which aren’t in your sample xml.

To extract the same data from your sample xml with lxml, change your expressions to

JavaScript

to get

JavaScript

and to

JavaScript

to get

JavaScript
User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement