Home > OS >  How to capture datalayer object and print in my eclipse console using selenium
How to capture datalayer object and print in my eclipse console using selenium

Time:09-09

I need to capture the datalayer from the console tab in the chrome developer tools


CodePudding user response:

Below code will help you to get data layer information

   JavascriptExecutor executor= (JavascriptExecutor)getDriver();

    ArrayList<Map<String, List<String> >> datalist = new ArrayList<>();

    //Execute google tag manage in the console using javascript executor to fetch values       
    datalist =  (ArrayList) executor.executeScript("return window.dataLayer");

    // Parse through GTM arrayList  
    for(int a=0; a < datalist .size(); a  ) {
        for (String key : datalist .get(a).keySet()) {
            System.out.println(key   "      "   datalist .get(a).get(key));

        }
    }
  • Related