Library version: | 3.0.4 |
---|---|
Library scope: | global |
Named arguments: | supported |
Robot Framework test library for verifying and modifying XML documents.html
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.python
The library has the following main usages:shell
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.express
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.app
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.框架
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.less
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.ide
The lxml support is new in Robot Framework 2.8.5.测试
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.
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.
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 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 child
elements, 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 |
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 |
The current element is denoted with a dot (.
). Normally the current element is implicit and does not need to be included in the xpath.
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 |
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 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.
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.
The tag of the element.
${root} = | Parse XML | ${XML} |
Should Be Equal | ${root.tag} | example |
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} |
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} |
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} |
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.
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.
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.
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.
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.
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 |
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 false
, none
or 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.
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 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. |
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
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 The Examples using
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 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 Examples using
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 If the copy or the original element is modified afterwards, the changes have no effect on the other. Examples using
|
|||||||||||||||||||||||||||||||||||
Element Attribute Should Be | source, name, expected,xpath=., message=None | Verifies that the specified attribute is The element whose attribute is verified is specified using The keyword passes if the attribute To test that the element does not have a certain attribute, Python Examples using
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 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
|
|||||||||||||||||||||||||||||||||||
Element Should Exist | source, xpath=.,message=None | Verifies that one or more element match the given Arguments 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 Arguments 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 The element whose attribute is verified is specified using The keyword fails if the specified element has attribute Examples using
See also Get Element Attribute, Get Element Attributes, Element 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 The element whose text is verified is specified using 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 The keyword passes if the text of the element is equal to the Examples using
|
|||||||||||||||||||||||||||||||||||
Element Text Should Match | source, pattern, xpath=.,normalize_whitespace=False,message=None | Verifies that the text of the specified element matches 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
|
|||||||||||||||||||||||||||||||||||
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 By default the string is returned as Unicode. If See also Log Element and Save XML. |
|||||||||||||||||||||||||||||||||||
Elements Should Be Equal | source, expected,exclude_children=False,normalize_whitespace=False | Verifies that the given Both The keyword passes if the All texts inside the given elements are verified, but possible text outside them is not. By default texts must match exactly, but setting Examples using
The last example may look a bit strange because the See also Elements Should Match. |
|||||||||||||||||||||||||||||||||||
Elements Should Match | source, expected,exclude_children=False,normalize_whitespace=False | Verifies that the given 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
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 The xpath expression to evaluate is given as Examples using
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 All the direct child elements of the specified element are returned. If the element has no children, an empty list is returned. Examples using
|
|||||||||||||||||||||||||||||||||||
Get Element | source, xpath=. | Returns an element in the The The keyword fails if more, or less, than one element matches the Examples using
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 The value of the attribute Examples using
See also Get Element Attributes, Element Attribute Should Be, Element 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 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
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 Arguments 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 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 Examples using
See also Get Elements Texts, Element Text Should Be and Element Text Should Match. |
|||||||||||||||||||||||||||||||||||
Get Elements | source, xpath | Returns a list of elements in the The Elements matching the Examples using
|
|||||||||||||||||||||||||||||||||||
Get Elements Texts | source, xpath,normalize_whitespace=False | Returns text of all elements matching The elements whose text to return is specified using The text of the matched elements is returned using the same logic as with Get Element Text. This includes optional whitespace normalization using the Examples using
|
|||||||||||||||||||||||||||||||||||
Log Element | source, level=INFO, xpath=. | Logs the string representation of the specified element. The element specified with 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 As discussed in Handling XML namespaces section, this keyword, by default, removes namespace information ElementTree has added to tag names and moves it into 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 Examples:
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 The element to remove from the The keyword fails if Element's tail text is not removed by default, but that can be changed by giving Examples using
|
|||||||||||||||||||||||||||||||||||
Remove Element Attribute | source, name, xpath=. | Removes attribute The element whose attribute to remove is specified using 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
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 Use Remove Element Attribute to remove a single attribute and Set Element Attribute to set them. Examples using
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 The elements to remove from the It is not a failure if Element's tail text is not removed by default, but that can be changed by using Examples using
|
|||||||||||||||||||||||||||||||||||
Remove Elements Attribute | source, name, xpath=. | Removes attribute Like Remove Element Attribute but removes the attribute of all elements matching the given 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 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 The file where the element is saved is denoted with The resulting XML file may not be exactly the same as the original:
Use Element To String if you just need a string representation of the element. |
|||||||||||||||||||||||||||||||||||
Set Element Attribute | source, name, value,xpath=. | Sets attribute The element whose attribute to set is specified using 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
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 Examples using
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 Element's text and tail text are changed only if new Examples using
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 Like Set Element Attribute but sets the attribute of all elements matching the given 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 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 New in Robot Framework 2.8.6. |
Altogether 37 keywords.
Generated by Libdoc on 2018-04-25 23:41:29.
图书馆版本: | 3.0.4 |
---|---|
图书馆范围: | 全球 |
命名参数: | 支持的 |
Robot Framework测试库,用于验证和修改XML文档。
顾名思义,XML是用于验证XML文件内容的测试库。实际上,它是Python的ElementTree XML API之上的一个很是薄的包装器。
该库具备如下主要用途:
可使用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上也可使用反斜杠,但它须要经过加倍(\\
)来转义它所需的测试数据。使用内置变量也很${/}
天然。
默认状况下,此库使用Python的标准ElementTree模块来解析XML,但能够将其配置为在导入库时使用lxml模块。不管使用哪一个模块进行解析,结果元素结构都具备相同的API。
使用lxml的主要好处是它支持比标准ElementTree更丰富的xpath语法,并容许使用Evaluate Xpath关键字。它还保留了保存XML的doctype和可能的名称空间前缀。
lxml支持是Robot Framework 2.8.5中的新增功能。
下面的简单示例演示了如何使用此库中的关键字以及BuiltIn和Collections库来解析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一次会更有效。
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/child
xpath将匹配全部这些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 XML和Get 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}和$ {空白} |
包含元素属性的Python字典。
$ {2nd} = | 获取元素 | $ {} XML | 第二 |
应该是平等的 | $ {2nd.attrib [ '身份证']} | 2 | |
$ {3rd} = | 获取元素 | $ {} XML | 第三 |
应该是空的 | $ {} 3rd.attrib |
ElementTree和lxml经过将名称空间URI添加到所谓的Clark Notation中的标记名称来处理XML文档中可能的名称空间。这对于xpaths来讲是不方便的,默认状况下,这个库会剥离这些名称空间并将它们移动到xmlns
属性。经过将keep_clark_notation
参数传递给Parse XML关键字能够避免这种状况。或者,Parse XML支持使用strip_namespaces
参数彻底剥离命名空间信息。下面更详细地讨论不一样方法的优缺点。
若是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和不使用时都处理名称空间。可是,与标准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 false
,none
或no
。不管其值如何,其余字符串都被视为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以前,全部非空字符串(包括false
和no
)都被认为是真的。none
在Robot Framework 3.0.3中考虑false是新的。
参数 | 文档 |
---|---|
use_lxml =假 | 导入库,启用了可选的lxml模式。 默认状况下,此库使用Python的标准ElementTree模块来解析XML。若是 使用lxml须要在系统上安装lxml模块。若是启用了lxml模式但未安装模块,则此库将发出警告并恢复使用标准ElementTree。 对lxml的支持是Robot Framework 2.8.5中的新增功能。 |
添加元素 · 清除元素 · copy元素 · 元素属性应该是 · 元素属性应该匹配 · 元素应该存在 · 元素应该不存在 · 元素应该没有属性 · 元素文字应该 · 元素文本应该匹配 · 元至字符串 · 元素应该相等 · 元素应该匹配 · 评估Xpath · 获取子元素 · 获取元素 ·获取元素属性 · 获取元素属性 · 获取元素计数 · 获取元素文本 · 获取元素 · 获取元素文本 · 日志元素 · 解析Xml · 删除元素 · 删除元素属性 · 删除元素属性 · 删除元素 · 删除元素属性 · 删除元素属性 · 保存Xml · 设置元素属性 · 设置元素标记 · 设置元素文本 ·设置元素属性 · 设置元素标签 · 设置元素文本
关键词 | 参数 | 文档 | |||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
添加元素 | source, element, index = None, xpath =。 | 将子元素添加到指定的元素。 要使用 所述 使用示例
|
|||||||||||||||||||||||||||||||||||
清除元素 | source, xpath =。, clear_tail =假 | 清除指定元素的内容。 要清除的元素使用 清除元素意味着删除其文本,属性和子元素。默认状况下不会删除元素的尾部文本,但能够经过给出 使用示例
使用“ 删除元素”删除整个元素。 |
|||||||||||||||||||||||||||||||||||
复制元素 | source, xpath =。 | 返回指定元素的副本。 要复制的元素使用 若是以后修改了副本或原始元素,则更改对另外一个没有影响。 使用示例
|
|||||||||||||||||||||||||||||||||||
元素属性应该是 | source, name, expected,xpath =。, 消息=无 | 验证指定的属性是否为 使用 若是 为了测试元素没有某个属性,Python 使用示例
|
|||||||||||||||||||||||||||||||||||
元素属性应该匹配 | 来源, 名称, 模式, xpath =。,消息=无 | 验证指定的属性是否匹配 此关键字的做用与“ 元素属性应该是的”彻底相同,只是能够将指望值做为元素属性必须匹配的模式给出。 模式匹配与shell中的匹配文件相似,而且始终区分大小写。在模式中,'*'匹配任何内容和'?' 匹配任何单个字符。 使用示例
|
|||||||||||||||||||||||||||||||||||
元素应该存在 | source, xpath =。, 消息=无 | 验证一个或多个元素是否与给定元素匹配 参数 |
|||||||||||||||||||||||||||||||||||
元素不该该存在 | source, xpath =。, 消息=无 | 验证没有元素与给定的匹配 参数 |
|||||||||||||||||||||||||||||||||||
元素不该该有属性 | source, name, xpath =。, 消息=无 | 验证指定的元素是否没有属性 使用 若是指定的元素具备属性,则关键字将失败 使用示例
|
|||||||||||||||||||||||||||||||||||
元素文本应该是 | source, expected, xpath =。,normalize_whitespace = False,message = None | 验证指定元素的文本是否为 验证文本的元素使用 要使用与Get Element Text相同的逻辑从指定的元素获取要验证的文本。这包括使用该 若是元素的文本等于 使用示例
|
|||||||||||||||||||||||||||||||||||
元素文本应该匹配 | source, pattern, xpath =。,normalize_whitespace = False,message = None | 验证指定元素的文本是否匹配 此关键字的工做方式与“ 元素文本应该”彻底相同,只是能够将指望值做为元素文本必须匹配的模式给出。 模式匹配与shell中的匹配文件相似,而且始终区分大小写。在模式中,'*'匹配任何内容和'?' 匹配任何单个字符。 使用示例
|
|||||||||||||||||||||||||||||||||||
元素到字符串 | source, xpath =。, encoding =无 | 返回指定元素的字符串表示形式。 要转换为字符串的元素是使用 默认状况下,字符串以Unicode格式返回。若是 |
|||||||||||||||||||||||||||||||||||
要素应该是平等的 | source, expected,exclude_children = False,normalize_whitespace = False | 验证给定 两者 若是 验证给定元素内的全部文本,但不包括它们以外的可能文本。默认状况下,文本必须彻底匹配,但设置 使用示例
最后一个示例可能看起来有点奇怪,由于该 另请参见元素应匹配。 |
|||||||||||||||||||||||||||||||||||
元素应该匹配 | source, expected,exclude_children = False,normalize_whitespace = False | 验证给定 此关键字的做用与Elements Should Be Equal彻底相同,只是指望值中的文本和属性值能够做为模式给出。 模式匹配与shell中的匹配文件相似,而且始终区分大小写。在模式中,'*'匹配任何内容和'?' 匹配任何单个字符。 使用示例
有关更多示例,请参阅元素应该相等。 |
|||||||||||||||||||||||||||||||||||
评估Xpath | 来源, 表达, 上下文=。 | 计算给定的xpath表达式并返回结果。 使用 要评估的xpath表达式做为 使用示例
仅当在导入库时使用lxml模式时,此关键字才有效。机器人框架2.8.5中的新功能。 |
|||||||||||||||||||||||||||||||||||
获取子元素 | source, xpath =。 | 以列表形式返回指定元素的子元素。 要返回的子元素使用 返回指定元素的全部直接子元素。若是元素没有子元素,则返回空列表。 使用示例
|
|||||||||||||||||||||||||||||||||||
获取元素 | source, xpath =。 | 返回 它 若是多于或少于一个元素匹配,则关键字失败 使用示例
当须要整个结构时,建议使用Parse XML来解析XML。若是须要配置XML命名空间的处理方式,则必须使用它。 许多其余关键字在内部使用此关键字,而且一般将修改XML的关键字记录到二者以修改给定的源并返回它。若是源是以字符串形式给出,则修改源不适用。而后返回基于字符串解析而后修改的XML结构。 |
|||||||||||||||||||||||||||||||||||
获取元素属性 | source, name, xpath =。, 默认=无 | 返回指定元素的命名属性。 要使用
使用示例
|
|||||||||||||||||||||||||||||||||||
获取元素属性 | source, xpath =。 | 返回指定元素的全部属性。 要返回的元素使用 属性做为Python字典返回。它是原始属性的副本,所以修改它对XML结构没有影响。 使用示例
使用“ 获取元素属性”获取单个属性的值。 |
|||||||||||||||||||||||||||||||||||
获取元素计数 | source, xpath =。 | 返回并记录给定 参数 |
|||||||||||||||||||||||||||||||||||
获取元素文本 | source, xpath =。,normalize_whitespace = False | 返回元素的全部文本,多是空格规范化的。 要返回的文本的元素是使用 此关键字返回指定元素的全部文本,包括其子元素和孙子元素包含的全部文本。若是元素没有文本,则返回空字符串。所以,返回的文本并不老是与元素的text属性相同。 默认状况下,元素内的全部空格(包括换行符和缩进)都按原样返回。若是 使用示例
|
|||||||||||||||||||||||||||||||||||
获取元素 | source, xpath | 返回 它 匹配的元素将 使用示例
|
|||||||||||||||||||||||||||||||||||
获取元素文本 | source, xpath,normalize_whitespace = False | 返回 要返回的文本使用 使用与Get Element Text相同的逻辑返回匹配元素的文本。这包括使用该 使用示例
|
|||||||||||||||||||||||||||||||||||
日志元素 | source, level = INFO, xpath =。 | 记录指定元素的字符串表示形式。 使用 还会返回记录的字符串。 |
|||||||||||||||||||||||||||||||||||
解析Xml | source, keep_clark_notation = False, strip_namespaces = False | 将给定的XML文件或字符串解析为元素结构。 的 正如在处理XML名称空间部分中所讨论的那样,默认状况下,此关键字会删除ElementTree添加到标记名称并将其移动到 若是要彻底删除命名空间信息,以便即便保存XML也不包含它,您能够为 例子:
|
|||||||||||||||||||||||||||||||||||
删除元素 | source, xpath =, remove_tail = False |
使用与Get Element关键字相同的语义 若是关键字 默认状况下不会删除元素的尾部文本,但能够经过给出 使用示例
|
|||||||||||||||||||||||||||||||||||
删除元素属性 | source, name, xpath =。 |
要使用 删除不存在的属性并不是失败。使用“ 删除元素属性”删除全部属性,使用“ 设置元素属性”设置它们。 使用示例
只能从单个元素中删除属性。使用“ 删除元素属性”可在一次调用中删除多个元素的属性。 |
|||||||||||||||||||||||||||||||||||
删除元素属性 | source, xpath =。 | 从指定元素中删除全部属性。 要使用 使用“ 删除元素属性”删除单个属性,使用“ 设置元素属性”设置它们。 使用示例
只能从单个元素中删除属性。使用“ 删除元素属性”可在一次调用中删除多个元素的全部属性。 |
|||||||||||||||||||||||||||||||||||
删除元素 | source, xpath =, remove_tail = False |
要使用与Get Elements关键字相同的语义 若是 默认状况下不会删除元素的尾部文本,但可使用 使用示例
|
|||||||||||||||||||||||||||||||||||
删除元素属性 | source, name, xpath =。 |
与删除元素属性相似,但删除与给定匹配的全部元素的属性 Robot Framework 2.8.6中的新功能。 |
|||||||||||||||||||||||||||||||||||
删除元素属性 | source, xpath =。 | 从指定元素中删除全部属性。 与删除元素属性相似,但删除与给定匹配的全部元素的全部属性 Robot Framework 2.8.6中的新功能。 |
|||||||||||||||||||||||||||||||||||
保存Xml | 源, 路径, 编码= UTF-8 | 将给定元素保存到指定文件。
保存元素的文件用 生成的XML文件可能与原始文件不彻底相同:
若是您只须要元素的字符串表示,请使用Element To String。 |
|||||||||||||||||||||||||||||||||||
设置元素属性 | 来源, 名称, 价值, xpath =。 |
要使用 既能够设置新属性又能够覆盖现有属性。使用“ 删除元素属性”或“ 删除元素属性 ”将其删除。 使用示例
只能设置单个元素的属性。使用“ 设置元素属性”在一次调用中设置多个元素的属性。 |
|||||||||||||||||||||||||||||||||||
设置元素标记 | source, tag, xpath =。 | 设置指定元素的标记。 要使用 使用示例
只能设置单个元素的标记。使用“ 设置元素标记”在一次调用中设置多个元素的标记。 |
|||||||||||||||||||||||||||||||||||
设置元素文本 | source, text = None, tail = None, xpath =。 | 设置指定元素的文本和/或尾部文本。 要使用 仅当给出新值 使用示例
只能设置单个元素的文本/尾部。使用“ 设置元素文本”在一次调用中设置多个元素的文本/尾部。 |
|||||||||||||||||||||||||||||||||||
设置元素属性 | 来源, 名称, 价值, xpath =。 |
与Set Element Attribute相似,但设置与给定元素匹配的全部元素的属性 Robot Framework 2.8.6中的新功能。 |
|||||||||||||||||||||||||||||||||||
设置元素标记 | source, tag, xpath =。 | 设置指定元素的标记。 与Set Element Tag相似,但设置与给定匹配的全部元素的标记 Robot Framework 2.8.6中的新功能。 |
|||||||||||||||||||||||||||||||||||
设置元素文本 | source, text = None, tail = None, xpath =。 | 设置指定元素的文本和/或尾部文本。 与Set Element Text相似,但设置与给定元素匹配的全部元素的文本或尾部 Robot Framework 2.8.6中的新功能。 |
共有37个关键字。
由Libdoc于2018-04-25 23:41:29 生成。