1
<script> jQuery(function()
{jQuery("#chart").kendoChart({"chartArea":{"background":"#f7f7f7"}
"title":{"position":"top"}
"legend":{"visible":false}
"series":[{"name":"Consumption"
"color":"#0000FF"
"type":"column"
"data":["1320649","1301971","1312053","0","0","0","0"]}]
"seriesDefaults":{"column":{"stack":true}}
"categoryAxis":[{"labels":{"rotation":360
"visible":true}
"majorGridLines":{"visible":false}
"line":{"visible":false}
"title":{"text":"Date"}
"categories":["08/10 \n Mo"
"08/11 \n Tu"
"08/12 \n We"
"08/13 \n Th"
"08/14 \n Fr"
"08/15 \n Sa"
"08/16 \n Su"]}]
"valueAxis":[{"labels":{"format":"n0"}
"line":{"visible":false}
"title":{"text":"G"}}]
"tooltip":{"template":"#=kendo.toString(parseFloat(value)
 \u0027n0\u0027)#"
"visible":true}});}); 

This data is generating SVG charts.

This code is inside HTML. Also the values above are "," separated like title,legend,series etc.

I want the data from the data string. It has daily consumption values. I want each of them so that I can apply assert to check the success.

How can I get the number in some variable in my java code (webdriver)

Thanks in Advance

0

I first took the the above data in a string. then i used the regex to extract the

 "data":["1320649","1301971","1312053","0","0","0","0"]}]

part. After this i again used the regex to extract the numbers only and so on and so forth. It was tedious but it worked good.

I took regex according so that on any day if the string changes some how my code should be able to handle it.

Here is my code :

 WebElement ele = driver.findElement(By.xpath("//div[@id='statictics-chart-enforce-reload-wrapper']/script[1]"));
        String str = ele.getAttribute("innerHTML");
        String mydata = str;
        Pattern pattern = Pattern.compile("data\":\\[(.*?)]");
        Matcher matcher = pattern.matcher(str);
        if (matcher.find())
        {

            System.out.println(matcher.group(1));
            mydata=matcher.group(1);
        }

        String arr[] = mydata.split(",");
        for(int i=0;i<7;i++)
        {
            day[i]=Integer.parseInt(arr[i].replace("\"",""));
            System.out.println(day[i]);
        }

This way I am able to get the values.

Do let me know if any one has a more simpler version.

Thanks in Advance

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.