<script> jQuery(function()
"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"]}]

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

1 Answer 1


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


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())


        String arr[] = mydata.split(",");
        for(int i=0;i<7;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 and acknowledge you have read our privacy policy.

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