How to retrieve all elements between two nodes with a given class name in XPATH

Viewed 41

I extracted this code from tradingview, I want to get access to all the div elements using xpath between this two elements namely C1 indicator and C2 indicator: enter image description here

I tried the following but does not seems working. Any thoughts?

*[following-sibling::div[contains(@data-section-name,'C1 Indicator')] and preceding-sibling::div[contains(@data-section-name,'C2 Indicator')]
1 Answers

I think the point you missed here is that div elements containing the data-section-name attribute are not siblings, they are each inside another parent div elements with titleWrap class name. So, I guess you should search for siblings of those titleWrap divs, while these parent divs should be located by their child divs containing data-section-name attributes. Something like the following:

*[following-sibling::div[contains(@class,'titleWrap') and .//div[contains(@data-section-name,'C1 Indicator')]] and preceding-sibling::div[contains(@class,'titleWrap') and .//div[contains(@data-section-name,'C2 Indicator')]]

Related