I am fairly new to XPath.
The requirement is to create a XPath expression which returns a list of elements, rather than a single element. After that we apply custom logic to locate the required element in the list.
The individual element can be accessed using the below XPaths:
.//*[@id='reportListItemID0']/td[12]/a
.//*[@id='reportListItemID1']/td[12]/a
.//*[@id='reportListItemID2']/td[12]/a
.
.
.
.//*[@id='reportListItemID20']/td[12]/a
.//*[@id='reportListItemID21']/td[12]/a
Please let me know, how to write a XPath expression which would returns all the above elements.
I tried the below and they did not work:
.//*[@id='reportListItemID.']/td[12]/a
.//*[@id='reportListItemID..']/td[12]/a
.//*[@id='reportListItemID*']/td[12]/a
.//*[@id='reportListItemID**']/td[12]/a
Please let me know what I am missing.
You should use the starts-with()
function:
.//*[starts-with(@id,'reportListItemID')]/td[12]/a
You can also use contains:
//*[contains(@id, 'reportListItemID')]/td[12]/a
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With