Himanshu
Himanshu

Reputation: 1

How to get value from "text" tag which is inside SVG tag in selenium java

I am trying to get text value from inside SVG elements which are not visible on the graph. however, when I mouse hover on it, it gives the tooltip value

I am able to mouse hover on the element but unable to get the value.

@FindBy(how=How.XPATH,using = "//*[name()='svg']//*[name()='g']//*[contains(@class,'')]//*[@visibility='hidden']")
    public static WebElement newgraph;

new Actions(driver).moveToElement(newgraph).clickAndHold().moveByOffset(0, 0).pause(1000).perform();
    /*    Actions builder = new Actions(driver);
        builder.moveToElement(newgraph).perform();*/
        String tooltip_msg = newgraph.getText();
        System.out.println(tooltip_msg);

Below is the HTML

<g class="highcharts-label highcharts-tooltip highcharts-color-undefined" 
style="cursor:default;pointer-events:none;white-space:nowrap;" 
transform="translate(212,-9999)" opacity="0" visibility="visible"><path 
fill="none" class="highcharts-label-box highcharts-tooltip-box" 
isShadow="true" stroke="#000000" stroke-opacity="0.049999999999999996" 
stroke-width="5" transform="translate(1, 1)"><text x="8" style="font- 
size:12px;color:#333333;fill:#333333;" y="20">

<tspan style="font-weight:bold; fill:#4fb3c3">Licensed: </tspan><tspan 
style="font-weight:bold" dx="0">560</tspan><tspan x="8" dy="15">May 24, 
2019</tspan></text>
</g>
</svg>

Upvotes: 0

Views: 1307

Answers (1)

cruisepandey
cruisepandey

Reputation: 29362

You can try with this xpath :

//*[local-name() = 'svg']/*/*/*/*[name()='tspan'][3]

It's locating the node that you want.

Just find the web element with that use .getText() to extract the date.

Let me know, if you have any more concerns.

Upvotes: 1

Related Questions