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 