I'm new to using selenium and I've hit a roadblock that I could really use some expert advice on.
Here is the HTML code I'm working with:
<div id='d3_tree'>
<svg>
<g transform="translate(20,50)>
<g class='node'>
</g>
<g class='node pe_node'>
</g>
<g class='node pe_node'>
</g>
</g>
</svg>
</div>
I need to target all the <g>
elements with the class pe_node
and trigger a context menu on them. Here's what I've tried:
node = self.driver.find_elements(By.XPATH, "//div[@id='d3_tree']/'svg']/g")
I then learned that SVG elements cannot be selected directly, so I attempted these alternatives:
nodes = self.driver.find_elements(By.XPATH, "//div[@id='d3_tree']/*[name()='svg']/g")
and
nodes = self.driver.find_elements(By.XPATH, "//div[@id='d3_tree']/*[local-name()='svg']/g")
Unfortunately, none of these solutions are yielding the results I expected, as I am getting an empty list ([]
) in return.
If anyone can provide guidance on how to specifically select the <g>
elements with the class pe_node
within the SVG, I would greatly appreciate it.
Thank you for any assistance.