FindChildByXPath method to find a child web element by the values of the element’s attributes. The search condition is specified using the XPath syntax.TestComplete first searches the child objects and if nothing is found, continues the search at deeper levels of the object hierarchy (in XPath terms, it searches through the descendants of the specified node).
The method returns the first found object that matches the specified condition. To get several elements, use the
|The function searches by the names of HTML elements and attributes. It does not use object names that are displayed in the Object Browser panel.
The function finds only web page elements. It does not find and return internal objects of Flash or Silverlight applications embedded into the tested web page.
The function does not find objects in
Note that the function uses the element’s attributes, not properties. The attributes can be specified in the HTML code, or they can be added to the element by the
|TestObj||A variable, parameter or expression that specifies a reference to one of the objects listed in the Applies To section|
|SearchInFrames||[in]||Optional||Boolean||Default value: True|
|Result||An object or a null object|
The method is applied to the following object:
To view this method in the Object Browser panel and in other panels and dialogs, activate the Advanced view mode.
The method has the following parameters:
Specifies the XPath search expression.
The following requirements must be met for the specified expression:
The search expression must comply with the XPath rules. For more information on them, see XPath documentation. For instance, you can find XPath Reference in the MSDN Library.
The search expression must contain the names of HTML elements and attributes. The function does not use object names that are displayed in the Object Browser panel.
The element and attributes names in the search expression are case-insensitive. That is, you can specify them either in the upper case, or in the lower case.
However, the element and attribute values, which you specify in the search expression, are case-sensitive. For instance, image1.PNG, IMAGE1.PNG and Image1.png are different values for XPath. The search expression must specify values in the same case, in which they are specified in the source code of the page. To create case-insensitive search expressions, use XPath’s
//IMG[translate(@src, 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') = 'image1.png']
See the documentation of XPath’s
translatefunction in the MSDN Library for complete information about this function and its parameters.
In search expressions, you can use XPath 1.0 functions like
XPath 2.0 functions (like
matches()and others), Microsoft extensions and other third-party extensions to XPath functions are not supported.
The table below contains some examples of XPath expressions that can be passed through the XPath parameter to search for web page elements matching the desired search criteria. Also, in the “Tips on Using XPath Expressions” section of the Finding Web Objects Using XPath Expressions topic, you can find some tips on specifying XPath expressions for the
||All IMG elements whose src attribute contains the plusBtn.gif substring.|
||All P elements that are located at the first position within
||All web page elements that have the align attribute set to center.|
||A collection of direct children of any UL element.|
||The last LI element within the UL element that has the id attribute set to ProductList.|
||All A elements that are descendants of any DIV element.|
Specifies whether the function should search within the frames' content. If it is True (default),
FindChildByXPath will search within the whole object hierarchy. If it is False, the content of the frames will be excluded from the search.
FindChildByXPath function searches for all the web elements, including those that are not displayed in the Object Tree. It finds a set of objects that match the search criteria and then returns the result using the following rules:
- If only one element matches the search condition, the function returns this object.
If several elements match the search condition, the function returns the first found object that resides in the Object Tree. If none of the found objects resides in the Object Tree, the function returns the first element from the found set.
If the search failed,
FindChildByXPathreturns a null object (
To search for multiple objects, use the
To view the example that demonstrates how you can use the
FindChildByXPath method to search for a web page element by one of its attributes, see Finding Web Objects Using XPath Expressions.