Get path in svg using Selenium (Python)

I have the following code that finds all g in svg, but how can I get these path elements inside g and their path value?

I am testing this site: http://www.totalcorner.com/match/live_stats/57565755

related code:

nodes = self.driver.find_elements_by_xpath("//div[@id='all_container']/*[@id='highcharts-0']/*[name()='svg']/*[name()='g']")

I already tried this:

nodes = self.driver.find_elements_by_xpath("//div[@id='all_container']/*[@id='highcharts-0']/*[name()='svg']/*[name()='g']/*[name()='path']")

but I get something like this:

[<selenium.webdriver.remote.webelement.WebElement (session="fb86fb35-d2fa-974a-af32-a15db1b7459d", element="{c1dad34f-764d-0249-9302-215dd9ae9cd8}")>, <selenium.webdriver.remote.webelement.WebElement (session="fb86fb35-d2fa-974a-af32-a15db1b7459d", element="{a53816f4-9952-ab49-87ac-5d79538a855d}")>, ...]

How can I use this to find the value of a path? many thanks

My updated solution:

Thanks to everyone. After Robert Longson's answer, I think the best solution is:

nodes = driver.find_elements_by_xpath("//div[@id='all_container']/*[@id='highcharts-0']/*[name()='svg']/*[name()='g']/*[name()='path']")
for node in nodes:
    print(node.get_attribute("d"))

Since I cannot distinguish paths using driver.find_elements_by_tag_name, I think the answer is above.

+4
source share
2 answers

You get a list, so try:

for node in nodes:
    print(node.text)

, (href ):

print(node.get_attribute('href'))
+3

find_elements_by_tag_name .

, get_attribute ( "d" ) .

.

for node in nodes:
    paths = node.find_elements_by_tag_name("path")
    for path in paths:
        value = path.get_attribute("d") 
+2

Source: https://habr.com/ru/post/1651790/


All Articles