How to get the text of the child elements

Hello All,

I need to get the texts Aug 12, Aug 13, Aug 14 etc shown below in a list.

Basically, i want to get the text of all the tspan tag under the g tag highlighted.
(The x value in text tag is dynamic and keeps varying for every session)
Please guide me.
Thanks in advance.

Unless I’m mistaken, that’s SVG. It’s possible too the content is not “DOM aware”.

Did you try WebUI.getText() ? I believe it uses the DOM API innerText but I don’t think SVG elements support it.

The only site I know well that uses SVG elements is tiddlywiki.com. I include this screenshot to show you my debugging. (By the way, I added the id “russ” to make life easier for me)

If you want to progress your test and need help with the JavaScript, let me know.

@Russ_Thomas Yes this is SVG.
I tried with the below code but don’t know how to proceed further -
private static void compareChartDataWithTable(){

TestObject selector_datapoints = new TestObject().addProperty(
‘xpath’, com.kms.katalon.core.testobject.ConditionType.EQUALS, ‘//div[@id=“container”]/div/[local-name()=“svg”]/[local-name()=“g” and contains(@class, “highcharts-axis-labels”) and contains(@class, “highcharts-xaxis-labels”)]’,
true)

List datapoints = WebUI.findWebElements(selector_datapoints, 30)

} 

I’m not sure my approach is correct, but I want all the date object in that List and then I was planning to use getText().
Looks like I’m missing out something.
Please guide me.

Solved it with below code -

private static void compareChartDataWithTable(){

	TestObject selector_datapoints = new TestObject().addProperty(
			'xpath', com.kms.katalon.core.testobject.ConditionType.EQUALS, '//div[@id="container"]/div/*[local-name()="svg"]/*[local-name()="g" and contains(@class, "highcharts-axis-labels") and contains(@class, "highcharts-xaxis-labels")]',
			true)
	
	
	List<WebElement> datapoints = WebUI.findWebElements(selector_datapoints, 30)
	for(int i = 0; i < datapoints.size; i++){
		KeywordUtil.logInfo(datapoints[i].getText())
		}
	
}

Result :
2020-08-27 12:25:41.585 DEBUG testcase.Check SP Keywords Dashboard - 5: *******.VerifyChartData.compareChartDataWithTable()
2020-08-27 12:25:46.641 INFO com.kms.katalon.core.util.KeywordUtil - Aug 13
Aug 14
Aug 15
Aug 16
Aug 17
Aug 18
Aug 19
Aug 20
Aug 21
Aug 22
Aug 23
Aug 24
Aug 25
Aug 26
2020-08-27 12:25:46.643 INFO k.k.c.m.CustomKeywordDelegatingMetaClass - *******.VerifyChartData.compareChartDataWithTable is PASSED

1 Like

Cool. And well done! Thanks for posting your solution :clap: