XML

Library version: 3.0.4
Library scope: global
Named arguments: supported

Introduction

Robot Framework test library for verifying and modifying XML documents.

As the name implies, XML is a test library for verifying contents of XML files. In practice it is a pretty thin wrapper on top of Python's ElementTree XML API.

The library has the following main usages:

Table of contents

Parsing XML

XML can be parsed into an element structure using Parse XML keyword. It accepts both paths to XML files and strings that contain XML. The keyword returns the root element of the structure, which then contains other elements as its children and their children. Possible comments and processing instructions in the source XML are removed.

XML is not validated during parsing even if has a schema defined. How possible doctype elements are handled otherwise depends on the used XML module and on the platform. The standard ElementTree strips doctypes altogether but when using lxml they are preserved when XML is saved. With IronPython parsing XML with a doctype is not supported at all.

The element structure returned by Parse XML, as well as elements returned by keywords such as Get Element, can be used as the source argument with other keywords. In addition to an already parsed XML structure, other keywords also accept paths to XML files and strings containing XML similarly as Parse XML. Notice that keywords that modify XML do not write those changes back to disk even if the source would be given as a path to a file. Changes must always saved explicitly using Save XML keyword.

When the source is given as a path to a file, the forward slash character (/) can be used as the path separator regardless the operating system. On Windows also the backslash works, but it the test data it needs to be escaped by doubling it (\\). Using the built-in variable ${/} naturally works too.

Using lxml

By default this library uses Python's standard ElementTree module for parsing XML, but it can be configured to use lxml module instead when importing the library. The resulting element structure has same API regardless which module is used for parsing.

The main benefits of using lxml is that it supports richer xpath syntax than the standard ElementTree and enables using Evaluate Xpath keyword. It also preserves the doctype and possible namespace prefixes saving XML.

The lxml support is new in Robot Framework 2.8.5.

Example

The following simple example demonstrates parsing XML and verifying its contents both using keywords in this library and in BuiltIn and Collections libraries. How to use xpath expressions to find elements and what attributes the returned elements contain are discussed, with more examples, in Finding elements with xpath and Element attributes sections.

In this example, as well as in many other examples in this documentation, ${XML} refers to the following example XML document. In practice ${XML} could either be a path to an XML file or it could contain the XML itself.

<example>
  <first id="1">text</first>
  <second id="2">
    <child/>
  </second>
  <third>
    <child>more text</child>
    <second id="child"/>
    <child><grandchild/></child>
  </third>
  <html>
    <p>
      Text with <b>bold</b> and <i>italics</i>.
    </p>
  </html>
</example>
${root} = Parse XML ${XML}    
Should Be Equal ${root.tag} example    
${first} = Get Element ${root} first  
Should Be Equal ${first.text} text    
Dictionary Should Contain Key ${first.attrib} id    
Element Text Should Be ${first} text    
Element Attribute Should Be ${first} id 1  
Element Attribute Should Be ${root} id 1 xpath=first
Element Attribute Should Be ${XML} id 1 xpath=first

Notice that in the example three last lines are equivalent. Which one to use in practice depends on which other elements you need to get or verify. If you only need to do one verification, using the last line alone would suffice. If more verifications are needed, parsing the XML with Parse XML only once would be more efficient.

Finding elements with xpath

ElementTree, and thus also this library, supports finding elements using xpath expressions. ElementTree does not, however, support the full xpath syntax, and what is supported depends on its version. ElementTree 1.3 that is distributed with Python 2.7 supports richer syntax than earlier versions.

The supported xpath syntax is explained below and ElementTree documentation provides more details. In the examples ${XML} refers to the same XML structure as in the earlier example.

If lxml support is enabled when importing the library, the whole xpath 1.0 standard is supported. That includes everything listed below but also lot of other useful constructs.

Tag names

When just a single tag name is used, xpath matches all direct child elements that have that tag name.

${elem} = Get Element ${XML} third
Should Be Equal ${elem.tag} third  
@{children} = Get Elements ${elem} child
Length Should Be ${children} 2  

Paths

Paths are created by combining tag names with a forward slash (/). For example, parent/child matches all child elements under parent element. Notice that if there are multiple parent elements that all have childelements, parent/child xpath will match all these child elements.

${elem} = Get Element ${XML} second/child
Should Be Equal ${elem.tag} child  
${elem} = Get Element ${XML} third/child/grandchild
Should Be Equal ${elem.tag} grandchild  

Wildcards

An asterisk (*) can be used in paths instead of a tag name to denote any element.

@{children} = Get Elements ${XML} */child
Length Should Be ${children} 3  

Current element

The current element is denoted with a dot (.). Normally the current element is implicit and does not need to be included in the xpath.

Parent element

The parent element of another element is denoted with two dots (..). Notice that it is not possible to refer to the parent of the current element. This syntax is supported only in ElementTree 1.3 (i.e. Python/Jython 2.7 and newer).

${elem} = Get Element ${XML} */second/..
Should Be Equal ${elem.tag} third  

Search all sub elements

Two forward slashes (//) mean that all sub elements, not only the direct children, are searched. If the search is started from the current element, an explicit dot is required.

@{elements} = Get Elements ${XML} .//second
Length Should Be ${elements} 2  
${b} = Get Element ${XML} html//b
Should Be Equal ${b.text} bold  

Predicates

Predicates allow selecting elements using also other criteria than tag names, for example, attributes or position. They are specified after the normal tag name or path using syntax path[predicate]. The path can have wildcards and other special syntax explained above.

What predicates ElementTree supports is explained in the table below. Notice that predicates in general are supported only in ElementTree 1.3 (i.e. Python/Jython 2.7 and newer).

Predicate Matches Example
@attrib Elements with attribute attrib. second[@id]
@attrib="value" Elements with attribute attrib having value value. *[@id="2"]
position Elements at the specified position. Position can be an integer (starting from 1), expression last(), or relative expression like last() - 1. third/child[1]
tag Elements with a child element named tag. third/child[grandchild]

Predicates can also be stacked like path[predicate1][predicate2]. A limitation is that possible position predicate must always be first.

Element attributes

All keywords returning elements, such as Parse XML, and Get Element, return ElementTree's Element objects. These elements can be used as inputs for other keywords, but they also contain several useful attributes that can be accessed directly using the extended variable syntax.

The attributes that are both useful and convenient to use in the test data are explained below. Also other attributes, including methods, can be accessed, but that is typically better to do in custom libraries than directly in the test data.

The examples use the same ${XML} structure as the earlier examples.

tag

The tag of the element.

${root} = Parse XML ${XML}
Should Be Equal ${root.tag} example

text

The text that the element contains or Python None if the element has no text. Notice that the text does not contain texts of possible child elements nor text after or between children. Notice also that in XML whitespace is significant, so the text contains also possible indentation and newlines. To get also text of the possible children, optionally whitespace normalized, use Get Element Text keyword.

${1st} = Get Element ${XML} first
Should Be Equal ${1st.text} text  
${2nd} = Get Element ${XML} second/child
Should Be Equal ${2nd.text} ${NONE}  
${p} = Get Element ${XML} html/p
Should Be Equal ${p.text} \n${SPACE*6}Text with${SPACE}  

tail

The text after the element before the next opening or closing tag. Python None if the element has no tail. Similarly as with text, also tail contains possible indentation and newlines.

${b} = Get Element ${XML} html/p/b
Should Be Equal ${b.tail} ${SPACE}and${SPACE}  

attrib

A Python dictionary containing attributes of the element.

${2nd} = Get Element ${XML} second
Should Be Equal ${2nd.attrib['id']} 2  
${3rd} = Get Element ${XML} third
Should Be Empty ${3rd.attrib}    

Handling XML namespaces

ElementTree and lxml handle possible namespaces in XML documents by adding the namespace URI to tag names in so called Clark Notation. That is inconvenient especially with xpaths, and by default this library strips those namespaces away and moves them to xmlns attribute instead. That can be avoided by passing keep_clark_notation argument to Parse XML keyword. Alternatively Parse XML supports stripping namespace information altogether by using strip_namespaces argument. The pros and cons of different approaches are discussed in more detail below.

How ElementTree handles namespaces

If an XML document has namespaces, ElementTree adds namespace information to tag names in Clark Notation (e.g. {http://ns.uri}tag) and removes original xmlns attributes. This is done both with default namespaces and with namespaces with a prefix. How it works in practice is illustrated by the following example, where ${NS} variable contains this XML document:

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                xmlns="http://www.w3.org/1999/xhtml">
  <xsl:template match="/">
    <html></html>
  </xsl:template>
</xsl:stylesheet>
${root} = Parse XML ${NS} keep_clark_notation=yes
Should Be Equal ${root.tag} {http://www.w3.org/1999/XSL/Transform}stylesheet  
Element Should Exist ${root} {http://www.w3.org/1999/XSL/Transform}template/{http://www.w3.org/1999/xhtml}html  
Should Be Empty ${root.attrib}    

As you can see, including the namespace URI in tag names makes xpaths really long and complex.

If you save the XML, ElementTree moves namespace information back to xmlns attributes. Unfortunately it does not restore the original prefixes:

<ns0:stylesheet xmlns:ns0="http://www.w3.org/1999/XSL/Transform">
  <ns0:template match="/">
    <ns1:html xmlns:ns1="http://www.w3.org/1999/xhtml"></ns1:html>
  </ns0:template>
</ns0:stylesheet>

The resulting output is semantically same as the original, but mangling prefixes like this may still not be desirable. Notice also that the actual output depends slightly on ElementTree version.

Default namespace handling

Because the way ElementTree handles namespaces makes xpaths so complicated, this library, by default, strips namespaces from tag names and moves that information back to xmlns attributes. How this works in practice is shown by the example below, where ${NS} variable contains the same XML document as in the previous example.

${root} = Parse XML ${NS}    
Should Be Equal ${root.tag} stylesheet    
Element Should Exist ${root} template/html    
Element Attribute Should Be ${root} xmlns http://www.w3.org/1999/XSL/Transform  
Element Attribute Should Be ${root} xmlns http://www.w3.org/1999/xhtml xpath=template/html

Now that tags do not contain namespace information, xpaths are simple again.

A minor limitation of this approach is that namespace prefixes are lost. As a result the saved output is not exactly same as the original one in this case either:

<stylesheet xmlns="http://www.w3.org/1999/XSL/Transform">
  <template match="/">
    <html xmlns="http://www.w3.org/1999/xhtml"></html>
  </template>
</stylesheet>

Also this output is semantically same as the original. If the original XML had only default namespaces, the output would also look identical.

Namespaces when using lxml

This library handles namespaces same way both when using lxml and when not using it. There are, however, differences how lxml internally handles namespaces compared to the standard ElementTree. The main difference is that lxml stores information about namespace prefixes and they are thus preserved if XML is saved. Another visible difference is that lxml includes namespace information in child elements got with Get Element if the parent element has namespaces.

Stripping namespaces altogether

Because namespaces often add unnecessary complexity, Parse XML supports stripping them altogether by using strip_namespaces=True. When this option is enabled, namespaces are not shown anywhere nor are they included if XML is saved.

Attribute namespaces

Attributes in XML documents are, by default, in the same namespaces as the element they belong to. It is possible to use different namespaces by using prefixes, but this is pretty rare.

If an attribute has a namespace prefix, ElementTree will replace it with Clark Notation the same way it handles elements. Because stripping namespaces from attributes could cause attribute conflicts, this library does not handle attribute namespaces at all. Thus the following example works the same way regardless how namespaces are handled.

${root} = Parse XML <root id="1" ns:id="2" xmlns:ns="http://my.ns"/>  
Element Attribute Should Be ${root} id 1
Element Attribute Should Be ${root} {http://my.ns}id 2

Boolean arguments

Some keywords accept arguments that are handled as Boolean values true or false. If such an argument is given as a string, it is considered false if it is either an empty string or case-insensitively equal to falsenoneor no. Other strings are considered true regardless their value, and other argument types are tested using the same rules as in Python.

True examples:

Parse XML ${XML} keep_clark_notation=True # Strings are generally true.
Parse XML ${XML} keep_clark_notation=yes # Same as the above.
Parse XML ${XML} keep_clark_notation=${TRUE} # Python True is true.
Parse XML ${XML} keep_clark_notation=${42} # Numbers other than 0 are true.

False examples:

Parse XML ${XML} keep_clark_notation=False # String false is false.
Parse XML ${XML} keep_clark_notation=no # Also string no is false.
Parse XML ${XML} keep_clark_notation=${EMPTY} # Empty string is false.
Parse XML ${XML} keep_clark_notation=${FALSE} # Python False is false.

Prior to Robot Framework 2.9, all non-empty strings, including false and no, were considered to be true. Considering none false is new in Robot Framework 3.0.3.

Importing

Arguments Documentation
use_lxml=False

Import library with optionally lxml mode enabled.

By default this library uses Python's standard ElementTree module for parsing XML. If use_lxml argument is given a true value (see Boolean arguments), the library will use lxml module instead. See Using lxml section for benefits provided by lxml.

Using lxml requires that the lxml module is installed on the system. If lxml mode is enabled but the module is not installed, this library will emit a warning and revert back to using the standard ElementTree.

The support for lxml is new in Robot Framework 2.8.5.

Shortcuts

Add Element · Clear Element · Copy Element · Element Attribute Should Be · Element Attribute Should Match · Element Should Exist · Element Should Not Exist · Element Should Not Have Attribute · Element Text Should Be ·Element Text Should Match · Element To String · Elements Should Be Equal · Elements Should Match · Evaluate Xpath · Get Child Elements · Get Element · Get Element Attribute · Get Element Attributes · Get Element Count ·Get Element Text · Get Elements · Get Elements Texts · Log Element · Parse Xml · Remove Element · Remove Element Attribute · Remove Element Attributes · Remove Elements · Remove Elements Attribute ·Remove Elements Attributes · Save Xml · Set Element Attribute · Set Element Tag · Set Element Text · Set Elements Attribute · Set Elements Tag · Set Elements Text

Keywords

Keyword Arguments Documentation
Add Element source, element,index=None, xpath=.

Adds a child element to the specified element.

The element to whom to add the new element is specified using source and xpath. They have exactly the same semantics as with Get Element keyword. The resulting XML structure is returned, and if the source is an already parsed XML structure, it is also modified in place.

The element to add can be specified as a path to an XML file or as a string containing XML, or it can be an already parsed XML element. The element is copied before adding so modifying either the original or the added element has no effect on the other . The element is added as the last child by default, but a custom index can be used to alter the position. Indices start from zero (0 = first position, 1 = second position, etc.), and negative numbers refer to positions at the end (-1 = second last position, -2 = third last, etc.).

Examples using ${XML} structure from Example:

Add Element ${XML} <new id="x"><c1/></new>    
Add Element ${XML} <c2/> xpath=new  
Add Element ${XML} <c3/> index=1 xpath=new
${new} = Get Element ${XML} new  
Elements Should Be Equal ${new} <new id="x"><c1/><c3/><c2/></new>    

Use Remove Element or Remove Elements to remove elements.

Clear Element source, xpath=.,clear_tail=False

Clears the contents of the specified element.

The element to clear is specified using source and xpath. They have exactly the same semantics as with Get Element keyword. The resulting XML structure is returned, and if the source is an already parsed XML structure, it is also modified in place.

Clearing the element means removing its text, attributes, and children. Element's tail text is not removed by default, but that can be changed by giving clear_tail a true value (see Boolean arguments). See Element attributes section for more information about tail in general.

Examples using ${XML} structure from Example:

Clear Element ${XML} xpath=first    
${first} = Get Element ${XML} xpath=first  
Elements Should Be Equal ${first} <first/>    
Clear Element ${XML} xpath=html/p/b clear_tail=yes  
Element Text Should Be ${XML} Text with italics. xpath=html/p normalize_whitespace=yes
Clear Element ${XML}      
Elements Should Be Equal ${XML} <example/>    

Use Remove Element to remove the whole element.

Copy Element source, xpath=.

Returns a copy of the specified element.

The element to copy is specified using source and xpath. They have exactly the same semantics as with Get Element keyword.

If the copy or the original element is modified afterwards, the changes have no effect on the other.

Examples using ${XML} structure from Example:

${elem} = Get Element ${XML} xpath=first
${copy1} = Copy Element ${elem}  
${copy2} = Copy Element ${XML} xpath=first
Set Element Text ${XML} new text xpath=first
Set Element Attribute ${copy1} id new
Elements Should Be Equal ${elem} <first id="1">new text</first>  
Elements Should Be Equal ${copy1} <first id="new">text</first>  
Elements Should Be Equal ${copy2} <first id="1">text</first>  
Element Attribute Should Be source, name, expected,xpath=., message=None

Verifies that the specified attribute is expected.

The element whose attribute is verified is specified using source and xpath. They have exactly the same semantics as with Get Element keyword.

The keyword passes if the attribute name of the element is equal to the expected value, and otherwise it fails. The default error message can be overridden with the message argument.

To test that the element does not have a certain attribute, Python None (i.e. variable ${NONE}) can be used as the expected value. A cleaner alternative is using Element Should Not Have Attribute.

Examples using ${XML} structure from Example:

Element Attribute Should Be ${XML} id 1 xpath=first
Element Attribute Should Be ${XML} id ${NONE}  

See also Element Attribute Should Match and Get Element Attribute.

Element Attribute Should Match source, name, pattern,xpath=., message=None

Verifies that the specified attribute matches expected.

This keyword works exactly like Element Attribute Should Be except that the expected value can be given as a pattern that the attribute of the element must match.

Pattern matching is similar as matching files in a shell, and it is always case-sensitive. In the pattern, '*' matches anything and '?' matches any single character.

Examples using ${XML} structure from Example:

Element Attribute Should Match ${XML} id ? xpath=first
Element Attribute Should Match ${XML} id c*d xpath=third/second
Element Should Exist source, xpath=.,message=None

Verifies that one or more element match the given xpath.

Arguments source and xpath have exactly the same semantics as with Get Elements keyword. Keyword passes if the xpath matches one or more elements in the source. The default error message can be overridden with the message argument.

See also Element Should Not Exist as well as Get Element Count that this keyword uses internally.

Element Should Not Exist source, xpath=.,message=None

Verifies that no element match the given xpath.

Arguments source and xpath have exactly the same semantics as with Get Elements keyword. Keyword fails if the xpath matches any element in the source. The default error message can be overridden with the message argument.

See also Element Should Exist as well as Get Element Count that this keyword uses internally.

Element Should Not Have Attribute source, name, xpath=.,message=None

Verifies that the specified element does not have attribute name.

The element whose attribute is verified is specified using source and xpath. They have exactly the same semantics as with Get Element keyword.

The keyword fails if the specified element has attribute name. The default error message can be overridden with the message argument.

Examples using ${XML} structure from Example:

Element Should Not Have Attribute ${XML} id  
Element Should Not Have Attribute ${XML} xxx xpath=first

See also Get Element AttributeGet Element AttributesElement Text Should Be and Element Text Should Match.

Element Text Should Be source, expected, xpath=.,normalize_whitespace=False,message=None

Verifies that the text of the specified element is expected.

The element whose text is verified is specified using source and xpath. They have exactly the same semantics as with Get Element keyword.

The text to verify is got from the specified element using the same logic as with Get Element Text. This includes optional whitespace normalization using the normalize_whitespace option.

The keyword passes if the text of the element is equal to the expected value, and otherwise it fails. The default error message can be overridden with the messageargument. Use Element Text Should Match to verify the text against a pattern instead of an exact value.

Examples using ${XML} structure from Example:

Element Text Should Be ${XML} text xpath=first
Element Text Should Be ${XML} ${EMPTY} xpath=second/child
${paragraph} = Get Element ${XML} xpath=html/p
Element Text Should Be ${paragraph} Text with bold and italics. normalize_whitespace=yes
Element Text Should Match source, pattern, xpath=.,normalize_whitespace=False,message=None

Verifies that the text of the specified element matches expected.

This keyword works exactly like Element Text Should Be except that the expected value can be given as a pattern that the text of the element must match.

Pattern matching is similar as matching files in a shell, and it is always case-sensitive. In the pattern, '*' matches anything and '?' matches any single character.

Examples using ${XML} structure from Example:

Element Text Should Match ${XML} t??? xpath=first
${paragraph} = Get Element ${XML} xpath=html/p
Element Text Should Match ${paragraph} Text with * and *. normalize_whitespace=yes
Element To String source, xpath=.,encoding=None

Returns the string representation of the specified element.

The element to convert to a string is specified using source and xpath. They have exactly the same semantics as with Get Element keyword.

By default the string is returned as Unicode. If encoding argument is given any value, the string is returned as bytes in the specified encoding. The resulting string never contains the XML declaration.

See also Log Element and Save XML.

Elements Should Be Equal source, expected,exclude_children=False,normalize_whitespace=False

Verifies that the given source element is equal to expected.

Both source and expected can be given as a path to an XML file, as a string containing XML, or as an already parsed XML element structure. See introduction for more information about parsing XML in general.

The keyword passes if the source element and expected element are equal. This includes testing the tag names, texts, and attributes of the elements. By default also child elements are verified the same way, but this can be disabled by setting exclude_children to a true value (see Boolean arguments).

All texts inside the given elements are verified, but possible text outside them is not. By default texts must match exactly, but setting normalize_whitespace to a true value makes text verification independent on newlines, tabs, and the amount of spaces. For more details about handling text see Get Element Text keyword and discussion about elements' text and tail attributes in the introduction.

Examples using ${XML} structure from Example:

${first} = Get Element ${XML} first  
Elements Should Be Equal ${first} <first id="1">text</first>    
${p} = Get Element ${XML} html/p  
Elements Should Be Equal ${p} <p>Text with <b>bold</b> and <i>italics</i>.</p> normalize_whitespace=yes  
Elements Should Be Equal ${p} <p>Text with</p> exclude normalize

The last example may look a bit strange because the <p> element only has text Text with. The reason is that rest of the text inside <p> actually belongs to the child elements. This includes the . at the end that is the tail text of the <i> element.

See also Elements Should Match.

Elements Should Match source, expected,exclude_children=False,normalize_whitespace=False

Verifies that the given source element matches expected.

This keyword works exactly like Elements Should Be Equal except that texts and attribute values in the expected value can be given as patterns.

Pattern matching is similar as matching files in a shell, and it is always case-sensitive. In the pattern, '*' matches anything and '?' matches any single character.

Examples using ${XML} structure from Example:

${first} = Get Element ${XML} first
Elements Should Match ${first} <first id="?">*</first>  

See Elements Should Be Equal for more examples.

Evaluate Xpath source, expression,context=.

Evaluates the given xpath expression and returns results.

The element in which context the expression is executed is specified using source and context arguments. They have exactly the same semantics as source and xpatharguments have with Get Element keyword.

The xpath expression to evaluate is given as expression argument. The result of the evaluation is returned as-is.

Examples using ${XML} structure from Example:

${count} = Evaluate Xpath ${XML} count(third/*)  
Should Be Equal ${count} ${3}    
${text} = Evaluate Xpath ${XML} string(descendant::second[last()]/@id)  
Should Be Equal ${text} child    
${bold} = Evaluate Xpath ${XML} boolean(preceding-sibling::*[1] = 'bold') context=html/p/i
Should Be Equal ${bold} ${True}    

This keyword works only if lxml mode is taken into use when importing the library. New in Robot Framework 2.8.5.

Get Child Elements source, xpath=.

Returns the child elements of the specified element as a list.

The element whose children to return is specified using source and xpath. They have exactly the same semantics as with Get Element keyword.

All the direct child elements of the specified element are returned. If the element has no children, an empty list is returned.

Examples using ${XML} structure from Example:

${children} = Get Child Elements ${XML}  
Length Should Be ${children} 4  
${children} = Get Child Elements ${XML} xpath=first
Should Be Empty ${children}    
Get Element source, xpath=.

Returns an element in the source matching the xpath.

The source can be a path to an XML file, a string containing XML, or an already parsed XML element. The xpath specifies which element to find. See the introduction for more details about both the possible sources and the supported xpath syntax.

The keyword fails if more, or less, than one element matches the xpath. Use Get Elements if you want all matching elements to be returned.

Examples using ${XML} structure from Example:

${element} = Get Element ${XML} second
${child} = Get Element ${element} child

Parse XML is recommended for parsing XML when the whole structure is needed. It must be used if there is a need to configure how XML namespaces are handled.

Many other keywords use this keyword internally, and keywords modifying XML are typically documented to both to modify the given source and to return it. Modifying the source does not apply if the source is given as a string. The XML structure parsed based on the string and then modified is nevertheless returned.

Get Element Attribute source, name, xpath=.,default=None

Returns the named attribute of the specified element.

The element whose attribute to return is specified using source and xpath. They have exactly the same semantics as with Get Element keyword.

The value of the attribute name of the specified element is returned. If the element does not have such element, the default value is returned instead.

Examples using ${XML} structure from Example:

${attribute} = Get Element Attribute ${XML} id xpath=first  
Should Be Equal ${attribute} 1      
${attribute} = Get Element Attribute ${XML} xx xpath=first default=value
Should Be Equal ${attribute} value      

See also Get Element AttributesElement Attribute Should BeElement Attribute Should Match and Element Should Not Have Attribute.

Get Element Attributes source, xpath=.

Returns all attributes of the specified element.

The element whose attributes to return is specified using source and xpath. They have exactly the same semantics as with Get Element keyword.

Attributes are returned as a Python dictionary. It is a copy of the original attributes so modifying it has no effect on the XML structure.

Examples using ${XML} structure from Example:

${attributes} = Get Element Attributes ${XML} first
Dictionary Should Contain Key ${attributes} id  
${attributes} = Get Element Attributes ${XML} third
Should Be Empty ${attributes}    

Use Get Element Attribute to get the value of a single attribute.

Get Element Count source, xpath=.

Returns and logs how many elements the given xpath matches.

Arguments source and xpath have exactly the same semantics as with Get Elements keyword that this keyword uses internally.

See also Element Should Exist and Element Should Not Exist.

Get Element Text source, xpath=.,normalize_whitespace=False

Returns all text of the element, possibly whitespace normalized.

The element whose text to return is specified using source and xpath. They have exactly the same semantics as with Get Element keyword.

This keyword returns all the text of the specified element, including all the text its children and grandchildren contain. If the element has no text, an empty string is returned. The returned text is thus not always the same as the text attribute of the element.

By default all whitespace, including newlines and indentation, inside the element is returned as-is. If normalize_whitespace is given a true value (see Boolean arguments), then leading and trailing whitespace is stripped, newlines and tabs converted to spaces, and multiple spaces collapsed into one. This is especially useful when dealing with HTML data.

Examples using ${XML} structure from Example:

${text} = Get Element Text ${XML} first
Should Be Equal ${text} text  
${text} = Get Element Text ${XML} second/child
Should Be Empty ${text}    
${paragraph} = Get Element ${XML} html/p
${text} = Get Element Text ${paragraph} normalize_whitespace=yes
Should Be Equal ${text} Text with bold and italics.  

See also Get Elements TextsElement Text Should Be and Element Text Should Match.

Get Elements source, xpath

Returns a list of elements in the source matching the xpath.

The source can be a path to an XML file, a string containing XML, or an already parsed XML element. The xpath specifies which element to find. See the introduction for more details.

Elements matching the xpath are returned as a list. If no elements match, an empty list is returned. Use Get Element if you want to get exactly one match.

Examples using ${XML} structure from Example:

${children} = Get Elements ${XML} third/child
Length Should Be ${children} 2  
${children} = Get Elements ${XML} first/child
Should Be Empty ${children}    
Get Elements Texts source, xpath,normalize_whitespace=False

Returns text of all elements matching xpath as a list.

The elements whose text to return is specified using source and xpath. They have exactly the same semantics as with Get Elements keyword.

The text of the matched elements is returned using the same logic as with Get Element Text. This includes optional whitespace normalization using the normalize_whitespace option.

Examples using ${XML} structure from Example:

@{texts} = Get Elements Texts ${XML} third/child
Length Should Be ${texts} 2  
Should Be Equal @{texts}[0] more text  
Should Be Equal @{texts}[1] ${EMPTY}  
Log Element source, level=INFO, xpath=.

Logs the string representation of the specified element.

The element specified with source and xpath is first converted into a string using Element To String keyword internally. The resulting string is then logged using the given level.

The logged string is also returned.

Parse Xml source,keep_clark_notation=False,strip_namespaces=False

Parses the given XML file or string into an element structure.

The source can either be a path to an XML file or a string containing XML. In both cases the XML is parsed into ElementTree element structure and the root element is returned. Possible comments and processing instructions in the source XML are removed.

As discussed in Handling XML namespaces section, this keyword, by default, removes namespace information ElementTree has added to tag names and moves it into xmlns attributes. This typically eases handling XML documents with namespaces considerably. If you do not want that to happen, or want to avoid the small overhead of going through the element structure when your XML does not have namespaces, you can disable this feature by giving keep_clark_notation argument a true value (see Boolean arguments).

If you want to strip namespace information altogether so that it is not included even if XML is saved, you can give a true value to strip_namespaces argument. This functionality is new in Robot Framework 3.0.2.

Examples:

${root} = Parse XML <root><child/></root>  
${xml} = Parse XML ${CURDIR}/test.xml keep_clark_notation=True
${xml} = Parse XML ${CURDIR}/test.xml strip_namespaces=True

Use Get Element keyword if you want to get a certain element and not the whole structure. See Parsing XML section for more details and examples.

Remove Element source, xpath=,remove_tail=False

Removes the element matching xpath from the source structure.

The element to remove from the source is specified with xpath using the same semantics as with Get Element keyword. The resulting XML structure is returned, and if the source is an already parsed XML structure, it is also modified in place.

The keyword fails if xpath does not match exactly one element. Use Remove Elements to remove all matched elements.

Element's tail text is not removed by default, but that can be changed by giving remove_tail a true value (see Boolean arguments). See Element attributes section for more information about tail in general.

Examples using ${XML} structure from Example:

Remove Element ${XML} xpath=second    
Element Should Not Exist ${XML} xpath=second    
Remove Element ${XML} xpath=html/p/b remove_tail=yes  
Element Text Should Be ${XML} Text with italics. xpath=html/p normalize_whitespace=yes
Remove Element Attribute source, name, xpath=.

Removes attribute name from the specified element.

The element whose attribute to remove is specified using source and xpath. They have exactly the same semantics as with Get Element keyword. The resulting XML structure is returned, and if the source is an already parsed XML structure, it is also modified in place.

It is not a failure to remove a non-existing attribute. Use Remove Element Attributes to remove all attributes and Set Element Attribute to set them.

Examples using ${XML} structure from Example:

Remove Element Attribute ${XML} id xpath=first
Element Should Not Have Attribute ${XML} id xpath=first

Can only remove an attribute from a single element. Use Remove Elements Attribute to remove an attribute of multiple elements in one call.

Remove Element Attributes source, xpath=.

Removes all attributes from the specified element.

The element whose attributes to remove is specified using source and xpath. They have exactly the same semantics as with Get Element keyword. The resulting XML structure is returned, and if the source is an already parsed XML structure, it is also modified in place.

Use Remove Element Attribute to remove a single attribute and Set Element Attribute to set them.

Examples using ${XML} structure from Example:

Remove Element Attributes ${XML} xpath=first  
Element Should Not Have Attribute ${XML} id xpath=first

Can only remove attributes from a single element. Use Remove Elements Attributes to remove all attributes of multiple elements in one call.

Remove Elements source, xpath=,remove_tail=False

Removes all elements matching xpath from the source structure.

The elements to remove from the source are specified with xpath using the same semantics as with Get Elements keyword. The resulting XML structure is returned, and if the source is an already parsed XML structure, it is also modified in place.

It is not a failure if xpath matches no elements. Use Remove Element to remove exactly one element.

Element's tail text is not removed by default, but that can be changed by using remove_tail argument similarly as with Remove Element.

Examples using ${XML} structure from Example:

Remove Elements ${XML} xpath=*/child
Element Should Not Exist ${XML} xpath=second/child
Element Should Not Exist ${XML} xpath=third/child
Remove Elements Attribute source, name, xpath=.

Removes attribute name from the specified elements.

Like Remove Element Attribute but removes the attribute of all elements matching the given xpath.

New in Robot Framework 2.8.6.

Remove Elements Attributes source, xpath=.

Removes all attributes from the specified elements.

Like Remove Element Attributes but removes all attributes of all elements matching the given xpath.

New in Robot Framework 2.8.6.

Save Xml source, path,encoding=UTF-8

Saves the given element to the specified file.

The element to save is specified with source using the same semantics as with Get Element keyword.

The file where the element is saved is denoted with path and the encoding to use with encoding. The resulting file always contains the XML declaration.

The resulting XML file may not be exactly the same as the original:

  • Comments and processing instructions are always stripped.
  • Possible doctype and namespace prefixes are only preserved when using lxml.
  • Other small differences are possible depending on the ElementTree or lxml version.

Use Element To String if you just need a string representation of the element.

Set Element Attribute source, name, value,xpath=.

Sets attribute name of the specified element to value.

The element whose attribute to set is specified using source and xpath. They have exactly the same semantics as with Get Element keyword. The resulting XML structure is returned, and if the source is an already parsed XML structure, it is also modified in place.

It is possible to both set new attributes and to overwrite existing. Use Remove Element Attribute or Remove Element Attributes for removing them.

Examples using ${XML} structure from Example:

Set Element Attribute ${XML} attr value  
Element Attribute Should Be ${XML} attr value  
Set Element Attribute ${XML} id new xpath=first
Element Attribute Should Be ${XML} id new xpath=first

Can only set an attribute of a single element. Use Set Elements Attribute to set an attribute of multiple elements in one call.

Set Element Tag source, tag, xpath=.

Sets the tag of the specified element.

The element whose tag to set is specified using source and xpath. They have exactly the same semantics as with Get Element keyword. The resulting XML structure is returned, and if the source is an already parsed XML structure, it is also modified in place.

Examples using ${XML} structure from Example:

Set Element Tag ${XML} newTag  
Should Be Equal ${XML.tag} newTag  
Set Element Tag ${XML} xxx xpath=second/child
Element Should Exist ${XML} second/xxx  
Element Should Not Exist ${XML} second/child  

Can only set the tag of a single element. Use Set Elements Tag to set the tag of multiple elements in one call.

Set Element Text source, text=None,tail=None, xpath=.

Sets text and/or tail text of the specified element.

The element whose text to set is specified using source and xpath. They have exactly the same semantics as with Get Element keyword. The resulting XML structure is returned, and if the source is an already parsed XML structure, it is also modified in place.

Element's text and tail text are changed only if new text and/or tail values are given. See Element attributes section for more information about text and tail in general.

Examples using ${XML} structure from Example:

Set Element Text ${XML} new text xpath=first  
Element Text Should Be ${XML} new text xpath=first  
Set Element Text ${XML} tail=& xpath=html/p/b  
Element Text Should Be ${XML} Text with bold&italics. xpath=html/p normalize_whitespace=yes
Set Element Text ${XML} slanted !! xpath=html/p/i
Element Text Should Be ${XML} Text with bold&slanted!! xpath=html/p normalize_whitespace=yes

Can only set the text/tail of a single element. Use Set Elements Text to set the text/tail of multiple elements in one call.

Set Elements Attribute source, name, value,xpath=.

Sets attribute name of the specified elements to value.

Like Set Element Attribute but sets the attribute of all elements matching the given xpath.

New in Robot Framework 2.8.6.

Set Elements Tag source, tag, xpath=.

Sets the tag of the specified elements.

Like Set Element Tag but sets the tag of all elements matching the given xpath.

New in Robot Framework 2.8.6.

Set Elements Text source, text=None,tail=None, xpath=.

Sets text and/or tail text of the specified elements.

Like Set Element Text but sets the text or tail of all elements matching the given xpath.

New in Robot Framework 2.8.6.

Altogether 37 keywords. 
Generated by Libdoc on 2018-04-25 23:41:29.

XML

图书馆版本: 3.0.4
图书馆范围: 全球
命名参数: 支持的

介绍

Robot Framework测试库,用于验证和修改XML文档。

顾名思义,XML是用于验证XML文件内容的测试库。实际上,它是Python的ElementTree XML API之上的一个非常薄的包装器。

该库具有以下主要用途:

目录

解析XML

可以使用Parse XML关键字将XML解析为元素结构。它接受XML文件的路径和包含XML的字符串。关键字返回结构的根元素,然后包含其他元素作为其子元素及其子元素。将删除源XML中可能的注释和处理指令。

即使已定义架构,在解析期间也不验证XML。如何处理doctype元素,否则取决于使用的XML模块和平台。标准的ElementTree完全剥离了doctypes,但是当使用lxml时,它们会在保存XML时保留。使用IronPython时,根本不支持使用doctype解析XML。

Parse XML返回的元素结构以及Get Elementsource等关键字返回的元素可以用作其他关键字的参数。除了已经解析的XML结构之外,其他关键字也接受XML文件的路径和包含XML的字符串,类似于Parse XML。请注意,修改XML的关键字不会将这些更改写回磁盘,即使源是作为文件的路径提供的。必须始终使用Save XML关键字显式保存更改。

当源作为文件的路径给出时,正斜杠字符(/)可以用作路径分隔符,而不管操作系统如何。在Windows上也可以使用反斜杠,但它需要通过加倍(\\)来转义它所需的测试数据。使用内置变量也很${/}自然。

使用lxml

默认情况下,此库使用Python的标准ElementTree模块来解析XML,但可以将其配置为在导入库时使用lxml模块。无论使用哪个模块进行解析,结果元素结构都具有相同的API。

使用lxml的主要好处是它支持比标准ElementTree更丰富的xpath语法,并允许使用Evaluate Xpath关键字。它还保留了保存XML的doctype和可能的名称空间前缀。

lxml支持是Robot Framework 2.8.5中的新增功能。

下面的简单示例演示了如何使用此库中的关键字以及BuiltInCollections库来解析XML并验证其内容。如何使用xpath表达式来查找元素以及返回的元素包含哪些属性,以及更多示例,在“ 使用xpath元素属性查找元素”部分中进行讨论。

在此示例中,以及本文档中的许多其他示例中,请${XML}参考以下示例XML文档。实际上,${XML}它可以是XML文件的路径,也可以包含XML本身。

<实例>
  <first id =“1”> text </ first>
  <second id =“2”>
    <子/>
  </秒>
  <第三>
    <child>更多文字</ child>
    <second id =“child”/>
    <子> <孙子/> </子>
  </第三>
  <HTML>
    <P>
      带<b>粗体</ b>和<i>斜体</ i>的文字。
    </ p>
  </ HTML>
</示例>
$ {root} = 解析XML $ {} XML    
应该是平等的 $ {} root.tag    
$ {first} = 获取元素 $ {}根 第一  
应该是平等的 $ {} first.text 文本    
字典应该包含密钥 $ {} first.attrib ID    
元素文本应该是 $ {}第一 文本    
元素属性应该是 $ {}第一 ID 1  
元素属性应该是 $ {}根 ID 1 的xpath =第一
元素属性应该是 $ {} XML ID 1 的xpath =第一

请注意,在示例中,最后三行是等效的。在实践中使用哪一个取决于您需要获取或验证的其他元素。如果您只需要进行一次验证,仅使用最后一行就足够了。如果需要更多验证,只使用Parse XML解析XML一次会更有效。

使用xpath查找元素

ElementTree以及此库也支持使用xpath表达式查找元素。但是,ElementTree不支持完整的xpath语法,支持的内容取决于其版本。随Python 2.7一起发布的ElementTree 1.3支持比早期版本更丰富的语法。

支持的xpath语法如下所述,ElementTree文档提供了更多详细信息。在示例中,${XML}引用与先前示例中相同的XML结构。

如果在导入库时启用了lxml支持,则支持整个xpath 1.0标准。这包括下面列出的所有内容,但也包括许多其他有用的结构。

标记名称

如果仅使用单个标记名称,则xpath将匹配具有该标记名称的所有直接子元素。

$ {elem} = 获取元素 $ {} XML 第三
应该是平等的 $ {} elem.tag 第三  
@ {children} = 获取元素 $ {} ELEM 儿童
应该是长度 $ {}儿童 2  

路径

通过将标记名称与正斜杠(/)组合来创建路径。例如,parent/child匹配child元素下的所有元素parent。请注意,如果有多个parent元素都具有child元素,则parent/childxpath将匹配所有这些child元素。

$ {elem} = 获取元素 $ {} XML 第二/儿童
应该是平等的 $ {} elem.tag 儿童  
$ {elem} = 获取元素 $ {} XML 第三个/孩子/孙子
应该是平等的 $ {} elem.tag 孙子  

通配符

*可以在路径中使用星号()而不是标记名称来表示任何元素。

@ {children} = 获取元素 $ {} XML */儿童
应该是长度 $ {}儿童 3  

当前元素

当前元素用点(.)表示。通常,当前元素是隐式的,不需要包含在xpath中。

父元素

另一个元素的父元素用两个点(..)表示。请注意,无法引用当前元素的父元素。仅在ElementTree 1.3(即Python / Jython 2.7及更高版本)中支持此语法。

$ {elem} = 获取元素 $ {} XML */第二/..
应该是平等的 $ {} elem.tag 第三  

搜索所有子元素

两个正斜杠(//)表示搜索所有子元素,而不仅仅是直接子元素。如果从当前元素开始搜索,则需要显式点。

@ {elements} = 获取元素 $ {} XML 。//第二
应该是长度 $ {}元素 2  
$ {b} = 获取元素 $ {} XML HTML // B
应该是平等的 $ {} b.text 胆大  

谓词

谓词允许使用除标签名称之外的其他标准来选择元素,例如,属性或位置。它们使用语法在普通标记名称或路径之后指定path[predicate]。该路径可以具有上面解释的通配符和其他特殊语法。

ElementTree支持的谓词在下表中说明。请注意,通常只在ElementTree 1.3中支持谓词(即Python / Jython 2.7和更新版本)。

谓词 火柴
@attrib 具有属性的元素attrib 第二[@id]
@属性=“值” 具有属性attrib值的元素value * [@ ID = “2”]
位置 指定位置的元素。位置可以是整数(从1开始),表达式last()或相对表达式last() - 1 第三/子[1]
标签 带有子元素的元素tag 第三/儿童[孙子]

谓词也可以堆叠起来path[predicate1][predicate2]。一个限制是可能的位置谓词必须始终是第一位的。

元素属性

返回元素的所有关键字(例如Parse XMLGet Element)都返回ElementTree的Element对象。这些元素可以用作其他关键字的输入,但它们还包含几个可以使用扩展变量语法直接访问的有用属性。

下面解释了在测试数据中使用既有用又方便的属性。还可以访问其他属性(包括方法),但这通常在自定义库中比直接在测试数据中更好。

这些示例使用与${XML}前面示例相同的结构。

标签

元素的标记。

$ {root} = 解析XML $ {} XML
应该是平等的 $ {} root.tag

文本

元素包含的文本或者None元素没有文本的Python 。请注意,文本包含可能的子元素的文本,也不包含子项之间或之间的文本。另请注意,在XML空格中很重要,因此文本还包含缩进和换行符。要获取可能子项的文本(可选择空格标准化),请使用“ 获取元素文本”关键字。

$ {1st} = 获取元素 $ {} XML 第一
应该是平等的 $ {} 1st.text 文本  
$ {2nd} = 获取元素 $ {} XML 第二/儿童
应该是平等的 $ {} 2nd.text $ {无}  
$ {p} = 获取元素 $ {} XML HTML / P
应该是平等的 $ {} p.text \ n $ {SPACE * 6}带$ {SPACE}的文字  

尾巴

在下一个打开或关闭标记之前的元素之后的文本。Python None如果元素没有尾部。与此类似text,还tail包含可能的缩进和换行符。

$ {b} = 获取元素 $ {} XML HTML / P / B
应该是平等的 $ {} b.tail $ {SPACE}和$ {空白}  

ATTRIB

包含元素属性的Python字典。

$ {2nd} = 获取元素 $ {} XML 第二
应该是平等的 $ {2nd.attrib [ '身份证']} 2  
$ {3rd} = 获取元素 $ {} XML 第三
应该是空的 $ {} 3rd.attrib    

处理XML名称空间

ElementTree和lxml通过将名称空间URI添加到所谓的Clark Notation中的标记名称来处理XML文档中可能的名称空间。这对于xpaths来说是不方便的,默认情况下,这个库会剥离这些名称空间并将它们移动到xmlns属性。通过将keep_clark_notation参数传递给Parse XML关键字可以避免这种情况。或者,Parse XML支持使用strip_namespaces参数完全剥离命名空间信息。下面更详细地讨论不同方法的优缺点。

ElementTree如何处理名称空间

如果XML文档具有名称空间,ElementTree会将名称空间信息添加到Clark Notation中的标记名称(例如{http://ns.uri}tag)并删除原始xmlns属性。使用默认命名空间和带前缀的命名空间都可以完成此操作。以下示例说明了它在实践中的工作原理,其中${NS}变量包含此XML文档:

<xsl:stylesheet xmlns:xsl =“http://www.w3.org/1999/XSL/Transform”
                的xmlns = “http://www.w3.org/1999/xhtml”>
  <xsl:template match =“/”>
    <HTML> </ HTML>
  </ XSL:模板>
</ XSL:样式>
$ {root} = 解析XML $ {} NS keep_clark_notation = YES
应该是平等的 $ {} root.tag {http://www.w3.org/1999/XSL/Transform}stylesheet  
元素应该存在 $ {}根 {http://www.w3.org/1999/XSL/Transform}template/{http://www.w3.org/1999/xhtml}html  
应该是空的 $ {} root.attrib    

正如您所看到的,在标记名称中包含名称空间URI会使xpath变得非常冗长和复杂。

如果保存XML,ElementTree会将名称空间信息移回xmlns属性。不幸的是它没有恢复原始前缀:

<ns0:stylesheet xmlns:ns0 =“http://www.w3.org/1999/XSL/Transform”>
  <ns0:template match =“/”>
    <ns1:html xmlns:ns1 =“http://www.w3.org/1999/xhtml”> </ ns1:html>
  </ NS0:模板>
</ NS0:样式>

结果输出在语义上与原始输出相同,但是这样的修改前缀可能仍然不可取。另请注意,实际输出略微取决于ElementTree版本。

默认命名空间处理

由于ElementTree处理命名空间的方式使xpath变得如此复杂,因此默认情况下,此库从标记名称中删除命名空间并将该信息移回xmlns属性。下面的示例显示了它在实践中的工作原理,其中${NS}变量包含与上一示例中相同的XML文档。

$ {root} = 解析XML $ {} NS    
应该是平等的 $ {} root.tag 样式表    
元素应该存在 $ {}根 模板/ HTML    
元素属性应该是 $ {}根 XMLNS http://www.w3.org/1999/XSL/Transform  
元素属性应该是 $ {}根 XMLNS http://www.w3.org/1999/xhtml 的xpath =模板/ HTML

现在标签不包含名称空间信息,xpath再次简单。

此方法的一个小限制是名称空间前缀丢失。因此,在这种情况下,保存的输出与原始输出不完全相同:

<stylesheet xmlns =“http://www.w3.org/1999/XSL/Transform”>
  <template match =“/”>
    <html xmlns =“http://www.w3.org/1999/xhtml”> </ html>
  </模板>
</样式表>

此输出在语义上也与原始输出相同。如果原始XML只有默认名称空间,则输出看起来也相同。

使用lxml时的命名空间

此库在使用lxml和不使用时都处理名称空间。但是,与标准ElementTree相比,lxml在内部处理命名空间的方式存在差异。主要区别在于lxml存储有关名称空间前缀的信息,因此如果保存XML则会保留它们。另一个明显的区别是,如果父元素具有名称空间,则lxml包含使用Get Element获取的子元素中的名称空间信息。

完全剥离命名空间

由于命名空间通常会增加不必要的复杂性,因此Parse XML支持使用完全剥离它们strip_namespaces=True。启用此选项后,如果保存XML,则名称空间不会显示在任何位置,也不会包含在名称空间中。

属性名称空间

默认情况下,XML文档中的属性与它们所属的元素位于相同的名称空间中。通过使用前缀可以使用不同的命名空间,但这种情况非常罕见。

如果属性具有名称空间前缀,则ElementTree将使用与处理元素相同的方式将其替换为Clark Notation。因为从属性中删除命名空间可能会导致属性冲突,所以此库根本不处理属性命名空间。因此,无论如何处理命名空间,以下示例的工作方式都相同。

$ {root} = 解析XML <root id =“1”ns:id =“2”xmlns:ns =“http://my.ns”/>  
元素属性应该是 $ {}根 ID 1
元素属性应该是 $ {}根 {HTTP://my.ns} ID 2

布尔参数

某些关键字接受以布尔值true或false处理的参数。如果这样的参数以字符串形式给出,则如果它是空字符串或不区分大小写,则被视为false falsenoneno。无论其值如何,其他字符串都被视为true,其他参数类型使用与Python相同的规则进行测试。

真实的例子:

解析XML $ {} XML keep_clark_notation =真 #字符串通常是正确的。
解析XML $ {} XML keep_clark_notation = YES #与上述相同。
解析XML $ {} XML keep_clark_notation = $ {TRUE} #Pcthon True是真的。
解析XML $ {} XML keep_clark_notation = $ {42} #0以外的数字为真。

错误的例子:

解析XML $ {} XML keep_clark_notation =假 #String false为false。
解析XML $ {} XML keep_clark_notation =无 #字符串no也是false。
解析XML $ {} XML keep_clark_notation = $ {EMPTY} #Empty字符串为false。
解析XML $ {} XML keep_clark_notation = $ {FALSE} #Python False是假的。

在Robot Framework 2.9之前,所有非空字符串(包括falseno)都被认为是真的。none在Robot Framework 3.0.3中考虑false是新的。

输入

参数 文档
use_lxml =假

导入库,启用了可选的lxml模式。

默认情况下,此库使用Python的标准ElementTree模块来解析XML。如果use_lxml参数被赋予真值(参见布尔参数),则库将使用lxml模块。有关lxml提供的好处,请参阅使用lxml部分。

使用lxml需要在系统上安装lxml模块。如果启用了lxml模式但未安装模块,则此库将发出警告并恢复使用标准ElementTree。

对lxml的支持是Robot Framework 2.8.5中的新增功能。

快捷键

添加元素 · 清除元素 · copy元素 · 元素属性应该是 · 元素属性应该匹配 · 元素应该存在 · 元素应该不存在 · 元素应该没有属性 · 元素文字应该 · 元素文本应该匹配 · 元至字符串 · 元素应该相等 · 元素应该匹配 · 评估Xpath · 获取子元素 · 获取元素 ·获取元素属性 · 获取元素属性 · 获取元素计数 · 获取元素文本 · 获取元素 · 获取元素文本 · 日志元素 · 解析Xml · 删除元素 · 删除元素属性 · 删除元素属性 · 删除元素 · 删除元素属性 · 删除元素属性 · 保存Xml · 设置元素属性 · 设置元素标记 · 设置元素文本 ·设置元素属性 · 设置元素标签 · 设置元素文本

关键词

关键词 参数 文档
添加元素 source, element, index = None, xpath =。

将子元素添加到指定的元素。

要使用source和指定要添加新元素的元素xpath。它们与Get Element关键字具有完全相同的语义。返回生成的XML结构,如果source是已经解析的XML结构,则也会对其进行修改。

所述element添加可以被指定为到XML文件的路径或作为含有XML字符串,或者它可以是一个已经被解析XML元素。在添加元素之前复制元素,因此修改原始元素或添加元素对另一元素没有影响。默认情况下,该元素作为最后一个子元素添加,但可以使用自定义索引来更改位置。指数从零开始(0 =第一个位置,1 =第二个位置等),负数指的是结尾处的位置(-1 =倒数第二个位置,-2 =倒数第三个位置等)。

使用示例${XML}结构的示例

添加元素 $ {} XML <new id =“x”> <c1 /> </ new>    
添加元素 $ {} XML <C2 /> XPath的=新  
添加元素 $ {} XML <C3 /> 索引= 1 XPath的=新
$ {new} = 获取元素 $ {} XML  
要素应该是平等的 $ {}新 <new id =“x”> <c1 /> <c3 /> <c2 /> </ new>    

使用“ 删除元素”或“ 删除元素”删除元素。

清除元素 source, xpath =。, clear_tail =假

清除指定元素的内容。

要清除的元素使用source和指定xpath。它们与Get Element关键字具有完全相同的语义。返回生成的XML结构,如果source是已经解析的XML结构,则也会对其进行修改。

清除元素意味着删除其文本,属性和子元素。默认情况下不会删除元素的尾部文本,但可以通过给出clear_tail一个真值来更改它(请参阅布尔参数)。有关尾部的更多信息,请参阅元素属性部分。

使用示例${XML}结构的示例

清除元素 $ {} XML 的xpath =第一    
$ {first} = 获取元素 $ {} XML 的xpath =第一  
要素应该是平等的 $ {}第一 <第一/>    
清除元素 $ {} XML 的xpath = HTML / P / B clear_tail = YES  
元素文本应该是 $ {} XML 带斜体的文字。 的xpath = HTML / P normalize_whitespace = YES
清除元素 $ {} XML      
要素应该是平等的 $ {} XML <示例/>    

使用“ 删除元素”删除整个元素。

复制元素 source, xpath =。

返回指定元素的副本。

要复制的元素使用source和指定xpath。它们与Get Element关键字具有完全相同的语义。

如果之后修改了副本或原始元素,则更改对另一个没有影响。

使用示例${XML}结构的示例

$ {elem} = 获取元素 $ {} XML 的xpath =第一
$ {copy1} = 复制元素 $ {} ELEM  
$ {copy2} = 复制元素 $ {} XML 的xpath =第一
设置元素文本 $ {} XML 新文本 的xpath =第一
设置元素属性 $ {} COPY1 ID
要素应该是平等的 $ {} ELEM <first id =“1”>新文字</ first>  
要素应该是平等的 $ {} COPY1 <first id =“new”> text </ first>  
要素应该是平等的 $ {} COPY2 <first id =“1”> text </ first>  
元素属性应该是 source, name, expectedxpath =。, 消息=无

验证指定的属性是否为expected

使用source和指定其属性已验证的元素xpath。它们与Get Element关键字具有完全相同的语义。

如果name元素的属性等于expected值,则关键字通过,否则失败。可以使用message参数覆盖默认错误消息。

为了测试元素没有某个属性,Python None(即变量${NONE})可以用作期望值。更清洁的替代方案是使用Element We Not Attribute

使用示例${XML}结构的示例

元素属性应该是 $ {} XML ID 1 的xpath =第一
元素属性应该是 $ {} XML ID $ {无}  

另请参见元素属性应匹配获取元素属性

元素属性应该匹配 来源, 名称, 模式, xpath =。消息=无

验证指定的属性是否匹配expected

此关键字的作用与“ 元素属性应该是的”完全相同,只是可以将期望值作为元素属性必须匹配的模式给出。

模式匹配与shell中的匹配文件类似,并且始终区分大小写。在模式中,'*'匹配任何内容和'?' 匹配任何单个字符。

使用示例${XML}结构的示例

元素属性应该匹配 $ {} XML ID 的xpath =第一
元素属性应该匹配 $ {} XML ID 光盘 的xpath =第三/第二
元素应该存在 source, xpath =。, 消息=无

验证一个或多个元素是否与给定元素匹配xpath

参数sourcexpath具有同样的语义与获取的元素关键字。如果xpath匹配中的一个或多个元素,则关键字传递source。可以使用message参数覆盖默认错误消息。

另请参见元素不应存在以及此关键字在内部使用的获取元素计数

元素不应该存在 source, xpath =。, 消息=无

验证没有元素与给定的匹配xpath

参数sourcexpath具有同样的语义与获取的元素关键字。如果xpath匹配中的任何元素,则关键字将失败source。可以使用message参数覆盖默认错误消息。

另请参见元素应存在以及此关键字在内部使用的获取元素计数

元素不应该有属性 source, name, xpath =。, 消息=无

验证指定的元素是否没有属性name

使用source和指定其属性已验证的元素xpath。它们与Get Element关键字具有完全相同的语义。

如果指定的元素具有属性,则关键字将失败name。可以使用message参数覆盖默认错误消息。

使用示例${XML}结构的示例

元素不应该有属性 $ {} XML ID  
元素不应该有属性 $ {} XML XXX 的xpath =第一

另请参阅获取元素属性获取元素属性元素文本应该元素文本应该匹配

元素文本应该是 source, expected, xpath =。normalize_whitespace = Falsemessage = None

验证指定元素的文本是否为expected

验证文本的元素使用source和指定xpath。它们与Get Element关键字具有完全相同的语义。

要使用与Get Element Text相同的逻辑从指定的元素获取要验证的文本。这包括使用该normalize_whitespace选项的可选空白规范化。

如果元素的文本等于expected值,则关键字通过,否则失败。可以使用message参数覆盖默认错误消息。使用元素文本应匹配以根据模式而不是精确值验证文本。

使用示例${XML}结构的示例

元素文本应该是 $ {} XML 文本 的xpath =第一
元素文本应该是 $ {} XML $ {EMPTY} 的xpath =第二/子
$ {paragraph} = 获取元素 $ {} XML 的xpath = HTML / P
元素文本应该是 $ {}段 带粗体和斜体的文字。 normalize_whitespace = YES
元素文本应该匹配 source, pattern, xpath =。normalize_whitespace = Falsemessage = None

验证指定元素的文本是否匹配expected

此关键字的工作方式与“ 元素文本应该”完全相同,只是可以将期望值作为元素文本必须匹配的模式给出。

模式匹配与shell中的匹配文件类似,并且始终区分大小写。在模式中,'*'匹配任何内容和'?' 匹配任何单个字符。

使用示例${XML}结构的示例

元素文本应该匹配 $ {} XML T 450 的xpath =第一
$ {paragraph} = 获取元素 $ {} XML 的xpath = HTML / P
元素文本应该匹配 $ {}段 带*和*的文字。 normalize_whitespace = YES
元素到字符串 source, xpath =。, encoding =无

返回指定元素的字符串表示形式。

要转换为字符串的元素是使用source和指定的xpath。它们与Get Element关键字具有完全相同的语义。

默认情况下,字符串以Unicode格式返回。如果encoding赋值为任何值,则字符串将以指定编码中的字节形式返回。结果字符串永远不会包含XML声明。

另请参见日志元素保存XML

要素应该是平等的 source, expectedexclude_children = Falsenormalize_whitespace = False

验证给定source元素是否等于expected

二者sourceexpected可以作为一个XML文件的路径,作为含XML字符串,或者作为已经被解析XML元素结构。有关解析XML的更多信息,请参阅简介

如果source元素和expected元素相等,则关键字通过。这包括测试元素的标签名称,文本和属性。默认情况下,也会以相同的方式验证子元素,但可以通过设置exclude_children为true值来禁用它(请参阅布尔参数)。

验证给定元素内的所有文本,但不包括它们之外的可能文本。默认情况下,文本必须完全匹配,但设置normalize_whitespace为true值会使文本验证独立于换行符,制表符和空格量。有关处理文本的更多详细信息,请参阅获取元素文本约元素的关键字和讨论文本尾部的属性介绍

使用示例${XML}结构的示例

$ {first} = 获取元素 $ {} XML 第一  
要素应该是平等的 $ {}第一 <first id =“1”> text </ first>    
$ {p} = 获取元素 $ {} XML HTML / P  
要素应该是平等的 $ {P} <p>带<b>粗体</ b>和<i>斜体</ i>的文字。</ p> normalize_whitespace = YES  
要素应该是平等的 $ {P} <p>带</ p>的文字 排除 正常化

最后一个示例可能看起来有点奇怪,因为该<p>元素只有文本Text with。原因是内部文本的其余部分<p>实际上属于子元素。这包括.最后一个元素的尾部文本<i>

另请参见元素应匹配

元素应该匹配 source, expectedexclude_children = Falsenormalize_whitespace = False

验证给定source元素是否匹配expected

此关键字的作用与Elements Should Be Equal完全相同,只是期望值中的文本和属性值可以作为模式给出。

模式匹配与shell中的匹配文件类似,并且始终区分大小写。在模式中,'*'匹配任何内容和'?' 匹配任何单个字符。

使用示例${XML}结构的示例

$ {first} = 获取元素 $ {} XML 第一
元素应该匹配 $ {}第一 <first id =“?”> * </ first>  

有关更多示例,请参阅元素应该相等

评估Xpath 来源, 表达, 上下文=。

计算给定的xpath表达式并返回结果。

使用sourcecontextarguments 指定执行表达式的上下文的元素。它们与Get Element关键字具有完全相同的语义sourcexpath参数。

要评估的xpath表达式作为expression参数给出。评估结果按原样返回。

使用示例${XML}结构的示例

$ {count} = 评估Xpath $ {} XML 计数(第三/ *)  
应该是平等的 $ {}计数 $ {3}    
$ {text} = 评估Xpath $ {} XML 串(后裔::第二[最后一个()] / @ id)的  
应该是平等的 $ {}文 儿童    
$ {bold} = 评估Xpath $ {} XML boolean(preceding-sibling :: * [1] ='bold') 上下文= HTML / P / I
应该是平等的 $ {}大胆 $ {TRUE}    

仅当在导入库时使用lxml模式时,此关键字才有效。机器人框架2.8.5中的新功能。

获取子元素 source, xpath =。

以列表形式返回指定元素的子元素。

要返回的子元素使用source和指定的元素xpath。它们与Get Element关键字具有完全相同的语义。

返回指定元素的所有直接子元素。如果元素没有子元素,则返回空列表。

使用示例${XML}结构的示例

$ {children} = 获取子元素 $ {} XML  
应该是长度 $ {}儿童 4  
$ {children} = 获取子元素 $ {} XML 的xpath =第一
应该是空的 $ {}儿童    
获取元素 source, xpath =。

返回source匹配的元素xpath

source可以是XML文件的路径,包含XML的字符串或已解析的XML元素。该xpath指定哪个元素找到。有关可能的源和支持的xpath语法的更多详细信息,请参阅简介

如果多于或少于一个元素匹配,则关键字失败xpath。如果要返回所有匹配的元素,请使用“ 获取元素”

使用示例${XML}结构的示例

$ {element} = 获取元素 $ {} XML 第二
$ {child} = 获取元素 $ {}元素 儿童

当需要整个结构时,建议使用Parse XML来解析XML。如果需要配置XML命名空间的处理方式,则必须使用它。

许多其他关键字在内部使用此关键字,并且通常将修改XML的关键字记录到两者以修改给定的源并返回它。如果源是以字符串形式给出,则修改源不适用。然后返回基于字符串解析然后修改的XML结构。

获取元素属性 source, name, xpath =。, 默认=无

返回指定元素的命名属性。

要使用source和指定要返回其属性的元素xpath。它们与Get Element关键字具有完全相同的语义。

name返回指定元素的属性值。如果元素没有这样的元素,default则返回该值。

使用示例${XML}结构的示例

$ {attribute} = 获取元素属性 $ {} XML ID 的xpath =第一  
应该是平等的 $ {}属性 1      
$ {attribute} = 获取元素属性 $ {} XML XX 的xpath =第一 默认=值
应该是平等的 $ {}属性      

另请参阅获取元素属性元素属性应该是元素属性应匹配元素不应具有属性

获取元素属性 source, xpath =。

返回指定元素的所有属性。

要返回的元素使用source和指定xpath。它们与Get Element关键字具有完全相同的语义。

属性作为Python字典返回。它是原始属性的副本,因此修改它对XML结构没有影响。

使用示例${XML}结构的示例

$ {attributes} = 获取元素属性 $ {} XML 第一
字典应该包含密钥 $ {}属性 ID  
$ {attributes} = 获取元素属性 $ {} XML 第三
应该是空的 $ {}属性    

使用“ 获取元素属性”获取单个属性的值。

获取元素计数 source, xpath =。

返回并记录给定xpath匹配的元素数。

参数source与此关键字内部使用的Get Elements关键字xpath具有完全相同的语义。

另请参见元素应存在元素不应存在

获取元素文本 source, xpath =。normalize_whitespace = False

返回元素的所有文本,可能是空格规范化的。

要返回的文本的元素是使用source和指定的xpath。它们与Get Element关键字具有完全相同的语义。

此关键字返回指定元素的所有文本,包括其子元素和孙子元素包含的所有文本。如果元素没有文本,则返回空字符串。因此,返回的文本并不总是与元素的text属性相同。

默认情况下,元素内的所有空格(包括换行符和缩进)都按原样返回。如果normalize_whitespace给出了一个真值(参见布尔参数),则删除前导和尾随空格,将换行符和制表符转换为空格,将多个空格折叠为一个空格。这在处理HTML数据时特别有用。

使用示例${XML}结构的示例

$ {text} = 获取元素文本 $ {} XML 第一
应该是平等的 $ {}文 文本  
$ {text} = 获取元素文本 $ {} XML 第二/儿童
应该是空的 $ {}文    
$ {paragraph} = 获取元素 $ {} XML HTML / P
$ {text} = 获取元素文本 $ {}段 normalize_whitespace = YES
应该是平等的 $ {}文 带粗体和斜体的文字。  

另请参阅获取元素文本元素文本应该元素文本应该匹配

获取元素 source, xpath

返回source匹配的元素列表xpath

source可以是XML文件的路径,包含XML的字符串或已解析的XML元素。该xpath指定哪个元素找到。有关详细信息,请参阅简介

匹配的元素将xpath作为列表返回。如果没有元素匹配,则返回空列表。如果您想获得一场比赛,请使用获取元素

使用示例${XML}结构的示例

$ {children} = 获取元素 $ {} XML 第三/儿童
应该是长度 $ {}儿童 2  
$ {children} = 获取元素 $ {} XML 第一个孩子
应该是空的 $ {}儿童    
获取元素文本 source, xpathnormalize_whitespace = False

返回xpath作为列表匹配的所有元素的文本。

要返回的文本使用source和指定的元素xpath。它们与Get Elements关键字具有完全相同的语义。

使用与Get Element Text相同的逻辑返回匹配元素的文本。这包括使用该normalize_whitespace选项的可选空白规范化。

使用示例${XML}结构的示例

@ {texts} = 获取元素文本 $ {} XML 第三/儿童
应该是长度 $ {}文本 2  
应该是平等的 @ {文本} [0] 更多文字  
应该是平等的 @ {文本} [1] $ {EMPTY}  
日志元素 source, level = INFO, xpath =。

记录指定元素的字符串表示形式。

使用source和指定的元素xpath首先在内部使用Element To String关键字转换为字符串。然后使用给定的字符串记录生成的字符串level

还会返回记录的字符串。

解析Xml source, keep_clark_notation = False, strip_namespaces = False

将给定的XML文件或字符串解析为元素结构。

source可以是XML文件或含XML字符串的路径。在这两种情况下,XML都被解析为ElementTree 元素结构,并返回根元素。将删除源XML中可能的注释和处理指令。

正如在处理XML名称空间部分中所讨论的那样,默认情况下,此关键字会删除ElementTree添加到标记名称并将其移动到xmlns属性中的名称空间信息。这通常可以显着简化处理带有名称空间的XML文档。如果您不希望这种情况发生,或者想要避免在XML没有名称空间时通过元素结构的小开销,则可以通过为keep_clark_notation参数赋予true值来禁用此功能(请参阅布尔参数)。

如果要完全删除命名空间信息,以便即使保存XML也不包含它,您可以为strip_namespaces参数赋予真值。此功能是Robot Framework 3.0.2中的新功能。

例子:

$ {root} = 解析XML <根> <子/> </根>  
$ {xml} = 解析XML $ {} CURDIR /test.xml keep_clark_notation =真
$ {xml} = 解析XML $ {} CURDIR /test.xml strip_namespaces =真

如果要获取某个元素而不是整个结构,请使用“ 获取元素”关键字。有关更多详细信息和示例,请参阅解析XML部分。

删除元素 source, xpath =, remove_tail = False

xpathsource结构中删除匹配的元素。

使用与Get Element关键字相同的语义source指定要从中删除的元素。返回生成的XML结构,如果是已经解析的XML结构,则也会对其进行修改。xpathsource

如果关键字xpath与一个元素不匹配,则关键字失败。使用“ 删除元素”删除所有匹配的元素。

默认情况下不会删除元素的尾部文本,但可以通过给出remove_tail一个真值来更改它(请参阅布尔参数)。有关尾部的更多信息,请参阅元素属性部分。

使用示例${XML}结构的示例

删除元素 $ {} XML 的xpath =第二    
元素不应该存在 $ {} XML 的xpath =第二    
删除元素 $ {} XML 的xpath = HTML / P / B remove_tail = YES  
元素文本应该是 $ {} XML 带斜体的文字。 的xpath = HTML / P normalize_whitespace = YES
删除元素属性 source, name, xpath =。

name从指定的元素中删除属性。

要使用source和指定要删除其属性的元素xpath。它们与Get Element关键字具有完全相同的语义。返回生成的XML结构,如果source是已经解析的XML结构,则也会对其进行修改。

删除不存在的属性并非失败。使用“ 删除元素属性”删除所有属性,使用“ 设置元素属性”设置它们。

使用示例${XML}结构的示例

删除元素属性 $ {} XML ID 的xpath =第一
元素不应该有属性 $ {} XML ID 的xpath =第一

只能从单个元素中删除属性。使用“ 删除元素属性”可在一次调用中删除多个元素的属性。

删除元素属性 source, xpath =。

从指定元素中删除所有属性。

要使用source和指定要删除的属性的元素xpath。它们与Get Element关键字具有完全相同的语义。返回生成的XML结构,如果source是已经解析的XML结构,则也会对其进行修改。

使用“ 删除元素属性”删除单个属性,使用“ 设置元素属性”设置它们。

使用示例${XML}结构的示例

删除元素属性 $ {} XML 的xpath =第一  
元素不应该有属性 $ {} XML ID 的xpath =第一

只能从单个元素中删除属性。使用“ 删除元素属性”可在一次调用中删除多个元素的所有属性。

删除元素 source, xpath =, remove_tail = False

xpathsource结构中删除所有匹配的元素。

要使用与Get Elements关键字相同的语义source指定要从中删除的元素。返回生成的XML结构,如果是已经解析的XML结构,则也会对其进行修改。xpathsource

如果xpath匹配没有元素,那不是失败。使用“ 删除元素”可以删除一个元素。

默认情况下不会删除元素的尾部文本,但可以使用remove_tail删除元素类似的参数来更改元素的尾部文本。

使用示例${XML}结构的示例

删除元素 $ {} XML XPath的= * /儿童
元素不应该存在 $ {} XML 的xpath =第二/子
元素不应该存在 $ {} XML XPath的=第三/儿童
删除元素属性 source, name, xpath =。

name从指定的元素中删除属性。

删除元素属性类似,但删除与给定匹配的所有元素的属性xpath

Robot Framework 2.8.6中的新功能。

删除元素属性 source, xpath =。

从指定元素中删除所有属性。

删除元素属性类似,但删除与给定匹配的所有元素的所有属性xpath

Robot Framework 2.8.6中的新功能。

保存Xml , 路径, 编码= UTF-8

将给定元素保存到指定文件。

source使用与Get Element关键字相同的语义指定要保存的元素

保存元素的文件用path以及要使用的编码表示encoding。生成的文件始终包含XML声明。

生成的XML文件可能与原始文件不完全相同:

  • 注释和处理指令始终被删除。
  • 只有在使用lxml时才会保留可能的doctype和名称空间前缀。
  • 其他细微差别可能取决于ElementTree或lxml版本。

如果您只需要元素的字符串表示,请使用Element To String

设置元素属性 来源, 名称, 价值, xpath =。

name将指定元素的属性设置为value

要使用source和指定要设置的属性的元素xpath。它们与Get Element关键字具有完全相同的语义。返回生成的XML结构,如果source是已经解析的XML结构,则也会对其进行修改。

既可以设置新属性又可以覆盖现有属性。使用“ 删除元素属性”或“ 删除元素属性 ”将其删除。

使用示例${XML}结构的示例

设置元素属性 $ {} XML ATTR  
元素属性应该是 $ {} XML ATTR  
设置元素属性 $ {} XML ID 的xpath =第一
元素属性应该是 $ {} XML ID 的xpath =第一

只能设置单个元素的属性。使用“ 设置元素属性”在一次调用中设置多个元素的属性。

设置元素标记 source, tag, xpath =。

设置指定元素的标记。

要使用source和指定要设置的标记的元素xpath。它们与Get Element关键字具有完全相同的语义。返回生成的XML结构,如果source是已经解析的XML结构,则也会对其进行修改。

使用示例${XML}结构的示例

设置元素标记 $ {} XML newTag  
应该是平等的 $ {} XML.tag newTag  
设置元素标记 $ {} XML XXX 的xpath =第二/子
元素应该存在 $ {} XML 第二/ XXX  
元素不应该存在 $ {} XML 第二/儿童  

只能设置单个元素的标记。使用“ 设置元素标记”在一次调用中设置多个元素的标记。

设置元素文本 source, text = None, tail = None, xpath =。

设置指定元素的文本和/或尾部文本。

要使用source和指定要设置的文本的元素xpath。它们与Get Element关键字具有完全相同的语义。返回生成的XML结构,如果source是已经解析的XML结构,则也会对其进行修改。

仅当给出新值text和/或tail值时,才会更改元素的文本和尾部文本。有关文本尾部的更多信息,请参阅元素属性部分。

使用示例${XML}结构的示例

设置元素文本 $ {} XML 新文本 的xpath =第一  
元素文本应该是 $ {} XML 新文本 的xpath =第一  
设置元素文本 $ {} XML 尾=& 的xpath = HTML / P / B  
元素文本应该是 $ {} XML 带粗体和斜体的文字。 的xpath = HTML / P normalize_whitespace = YES
设置元素文本 $ {} XML 倾斜 的xpath = HTML / P / I
元素文本应该是 $ {} XML 文字大胆倾斜! 的xpath = HTML / P normalize_whitespace = YES

只能设置单个元素的文本/尾部。使用“ 设置元素文本”在一次调用中设置多个元素的文本/尾部。

设置元素属性 来源, 名称, 价值, xpath =。

name将指定元素的属性设置为value

Set Element Attribute类似,但设置与给定元素匹配的所有元素的属性xpath

Robot Framework 2.8.6中的新功能。

设置元素标记 source, tag, xpath =。

设置指定元素的标记。

Set Element Tag类似,但设置与给定匹配的所有元素的标记xpath

Robot Framework 2.8.6中的新功能。

设置元素文本 source, text = None, tail = None, xpath =。

设置指定元素的文本和/或尾部文本。

Set Element Text类似,但设置与给定元素匹配的所有元素的文本或尾部xpath

Robot Framework 2.8.6中的新功能。

共有37个关键字。 
Libdoc于2018-04-25 23:41:29 生成。

04-05 08:25