Click here to Skip to main content
15,893,564 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I have a global javascript object variable. I want to get this variable by selenium webdriver in my console application.My script are in following
JavaScript
function Charts(x, y, name) {
             this.x = x;
             this.y = y;
             this.name = name;
             
         }
         var xax= ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"],
             yax= [[29.9, 71.5, 106.4, 129.2, 144, 176, 135.6, 148.5, 216.4, 194.1, 95.6, 54.4], [24, 70, 19, 128, 148, 178, 131, 140, 211, 190, 91, 50]],
             yname=["mon-data", "mon-data2"]

         var jsObj =
         [
             new Charts(xax, yax, yname)
         ];

From my console application i have tried to get the object by following way:

C#
public class ScriptObject
    {
        public string[] x;
        public string[][] y;      
        public string[] name;       
    }

C#
IJavaScriptExecutor js = driver as IJavaScriptExecutor;
Wait_Label:
var obj = (object)js.ExecuteScript("return window.jsObj;");
var Listobj = js.ExecuteScript("return window.jsObj;") as List<ScriptObject>;
string obstr = JsonConvert.SerializeObject(obj);

When i take the object with casting type object then i get the value but when i take the object as type of list i got nothing it remains null.

I need to set the object values into different arrays like the following
C#
public string[] x=obj.x;
public string[][] =obj.y;   
public string[] name =obj.name;  


How can extract the property of object and fulfill my purpose?
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900