Silk4NET supports a subset of the XPath query language to locate UI controls.
The following table lists the constructs that Silk4NET supports.
Supported Locator Construct | Sample | Description |
---|---|---|
// | //a |
Identifies objects that are descendants of the current object. The example identifies hyperlinks on a Web page. |
/ | /a |
Identifies objects that are direct children of the current object. Objects located on lower hierarchy levels are not recognized. The example identifies hyperlinks on a Web page that are direct children of the current object. |
Attribute | //a[@textContents='Home'] |
Identifies objects by a specific attribute. The example identifies hyperlinks with the text Home. |
Index |
Example 1: //a[3] Example 2: //a[@textContents='Home'][2] |
Identifies a specific occurrence of an object if there are multiple ones. Indices are 1-based in locators. Example 1 identifies the third hyperlink and Example 2 identifies the second hyperlink with the text Home. |
Logical Operators: and, or, not, =, != |
Example 1: //a[@textContents='Remove' or @textContents='Delete'] Example 2: //a[@textContents!='Remove'] Example 3: //a[not(@textContents='Delete' or @id='lnkDelete') and @href='*/delete'] |
Identifies objects by using logical operators to combine attributes. Example 1 identifies hyperlinks that either have the caption Remove or Delete, Example 2 identifies hyperlinks with a text that is not Remove, and Example 3 shows how to combine different logical operators. |
.. |
Example 1: //a[@textContents='Edit']/.. Example 2: //a[@textContents='Edit']/..//a[@textContents='Delete'] |
Identifies the parent of an object. Example 1 identifies the parent of the hyperlink with the text Edit and Example 2 identifies a hyperlink with the text Delete that has a sibling hyperlink with the text Edit. |
* |
Example 1: //*[@textContents='Home'] Example 2: /*/a |
Identifies objects without considering their types, like hyperlink, text field, or button. Example 1 identifies objects with the given text content, regardless of their type, and Example 2 identifies hyperlinks that are second-level descendants of the current object. |
The following table lists the locator constructs that Silk4NET does not support.
Unsupported Locator Construct | Example |
---|---|
Comparing two attributes with each other. | //a[@textContents = @id] |
An attribute name on the right side is not supported. An attribute name must be on the left side. | //a['abc' = @id] |
Combining multiple locators with and or or. | //a[@id = 'abc'] or ..//Checkbox |
More than one set of attribute brackets. |
//a[@id = 'abc'] [@textContents = '123']
(use //a [@id = 'abc' and @textContents = '123'] instead) |
More than one set of index brackets. | //a[1][2] |
Any construct that does not explicitly specify a class or the class wildcard, such as including a wildcard as part of a class name. |
//[@id = 'abc']
(use //*[@id = 'abc'] instead) "//*//a[@id='abc']" |