After iterating through a list of WebElements, which I refer to as 'graphs', and finding descendants within each graph, I am encountering an issue where similar descendants from different graphs are being included in the results. Currently, I am using By.cssSelector() to find these elements. Additionally, I need to access information from the parent of these descendants, making it difficult to isolate them using only css selectors.
Does anyone have an explanation for why this might be happening? Is there a method to first find the child elements and then trace back to their respective parents?
I was considering using a selector like graph.findElements(By.cssSelector(".child:parent"), but this type of selector is not valid in CSS.
If there is any confusion in my explanation, please let me know.
Thanks!
EDIT_1: To provide more context, here is the hierarchy I am dealing with:
<div class="graph">
<...several nested tags...>
<div class="parent">
<div class="child" />
<div class="child" />
</div>
<...several nested tags.../>
</div>
... (repeated for multiple 'graph' elements)
When using graph.findElements(By.cssSelector(".parent")), it returns a list of 3 WebElements when I actually only need 1. On the other hand, using graph.findElements(By.cssSelector(".child")) correctly returns a list of 2 WebElements.
EDIT_2:
Here is the specific information I need to extract:
From the parent element: I need to retrieve the class name, as it acts as a boolean value determining the element's appearance.
From the first child element: I require its visual attributes, determined by the boolean class name, as well as a single unique class name for easy identification.
From the second child element: I need to extract its textual content, without relying on an ID or class name for locating it.