XPath: Starts With
The starts-with() function in XPath is used to select elements whose attribute values or text content begin with a specified substring. This function is particularly useful when you need to match elements based on the beginning portion of an attribute or text.
You can use the following XPath:
This selects list items (li) within an unordered list (ul) where the class attribute starts with 'list-group-item'.
Example 1: //ul[@class='list-group']/li[starts-with(@class,'list-group-item')]
This targets list items where the id attribute starts with 'list-group-item'.
Example 2: //ul[@class='list-group']/li[starts-with(@id,'list-group-item')]
This selects list items whose text content begins with 'Sample Item'.
Example 3: //ul[@class='list-group']/li[starts-with(.,'Sample Item')]
- Sample Item 0001
- Sample Item 0002
- Sample Item 0003
- Sample Item 0004
- Sample Item 0005
- Sample Item 0006
- Sample Item 0007
- Sample Item 0008
- Sample Item 0009
- Sample Item 0010