I'm writing xpaths to select all the links under each category on left sidebar from following page: http://www.indexmundi.com/commodities/'>http://www.indexmundi.com/commodities/
I want to select the link under each category one by one. I've written the following xpath and it is selecting the link under first category(Commodity Price Indices) somehow. But I was wondering how I will select the links under other categories. I want to add a check on h3 tha if it's text is Energy, count and select all the rows before that, then if h3 text is Beverages, count and select all rows between Energy and Beverages
.//*[@id='dlCommodities']/tbody/tr[position()< count(following-sibling::tr/td/h3)-1]/td/a
Here is another xpath: .//*[@id='dlCommodities']/tbody/tr[preceding-sibling::tr/td/h3[. = 'Energy'] and following-sibling::tr/td/h3[. = 'Beverages']]/td/a
It is fulfilling the second requirement i.e. select rows between specific headings but it is missing one node.
Please help me fix these xpaths or suggest a better one.
Thanks