Selenium Unable to Perform Operations on SVG Elements

1.6k Views Asked by At

I am working on a web page which consists of 6 svg tags i have to verify each svg in that one is like the following one there are totally 26 paths in this i have to locate the 18th one

html is like this

    <div>
    <svg>
    <circle r="80" cy="80" cx="80" stroke="#f4f4f4" fill="#ffffff" class="svg-pie-outline"></circle>
<path transform="translate(80,80)" stroke-opacity="0" stroke="#21628e" fill-opacity="0.3" stroke-width="1" fill="#1f77b4" d="M4.572014716816786e-15,-74.66666666666667A74.66666666666667,74.66666666666667 0 1,1 -73.57464370459023,-12.723321691040942L-45.98415231536889,-7.952076056900588A46.666666666666664,46.666666666666664 0 1,0 2.8575091980104907e-15,-46.666666666666664Z" class="svg-pie-slice"></path>
<path transform="translate(80,80)" stroke-opacity="1" stroke="#8598b1" fill-opacity="1" stroke-width="1" fill="#aec7e8" d="M-73.57464370459023,-12.723321691040942A74.66666666666667,74.66666666666667 0 0,1 -34.86148247133797,-66.02869187718099L-21.78842654458623,-41.267932423238115A46.666666666666664,46.666666666666664 0 0,0 -45.98415231536889,-7.952076056900588Z" class="svg-pie-slice"></path>
<path transform="translate(80,80)" stroke-opacity="0" stroke="#ffffff" fill-opacity="0.3" stroke-width="1" fill="#ff7f0e" d="M-34.86148247133797,-66.02869187718099A74.66666666666667,74.66666666666667 0 0,1 -24.17659693792926,-70.64420196740863L-15.110373086205787,-44.152626229630386A46.666666666666664,46.666666666666664 0 0,0 -21.78842654458623,-41.267932423238115Z" class="svg-pie-slice"></path>
<path transform="translate(80,80)" stroke-opacity="0" stroke="#ffffff" fill-opacity="0.3" stroke-width="1" fill="#ffbb78" d="M-24.17659693792926,-70.64420196740863A74.66666666666667,74.66666666666667 0 0,1 -13.265702442700245,-73.47878775410526L-8.291064026687652,-45.92424234631578A46.666666666666664,46.666666666666664 0 0,0 -15.110373086205787,-44.152626229630386Z" class="svg-pie-slice"></path>

    </svg>
    </div>

I have the xpath to traverse till the paths but unable to locate the for each individual paths

This xpath will locate all the paths in the svg

html/body/div/div[1]/main/div/div[2]/div[3]/div[2]/ol[1]/li/article/div/div/div/div/div[1]/div/div/*[name()='svg']/*[name()='path']

it will traverse till all the paths unable to click on individual paths please help

didn't locate any paths in the list

html/body/div/div[1]/main/div/div[2]/div[3]/div[2]/ol[1]/li/article/div/div/div/div/div[1]/div/div/svg/path[18]

didn't locate any paths in the list

html/body/div/div[1]/main/div/div[2]/div[3]/div[2]/ol[1]/li/article/div/div/div/div/div[1]/div/div/*[name()='svg']/*[name()='path[2]']

didn't locate any paths in the list

html/body/div/div[1]/main/div/div[2]/div[3]/div[2]/ol[1]/li/article/div/div/div/div/div[1]/div/div/*[name()='svg']/*[name()='path']/*[name()='path']

please help

1

There are 1 best solutions below

0
On BEST ANSWER

After days of research i got the solution for accessing the svg elements

xpath for traversing to a particular element

.//*[@id='global-wrapper']/div[1]/main/div/div[2]/div[3]/div[1]/ol/li[1]/article/div/div/div/div/div[1]/div/*[name()='svg']/*[name()='path' and @fill='#aec7e8']

add a unique attribute to access the element in my case it was fill color