How to get the json response data from the Network tab under Preview using chromedriver

3,863 views
Skip to first unread message

Geo Martinez

unread,
Jan 24, 2020, 10:16:40 PM1/24/20
to Selenium Users

Screenshot (17).png

Hi , im looking for a way to get all the json response data from the Network Tab under Preview . In tried many ways and i can get only partial headers and some other stuff but not the required. Thanks in advance

⇜Krishnan Mahadevan⇝

unread,
Jan 24, 2020, 10:24:33 PM1/24/20
to Selenium Users
You could perhaps check if some of the techniques that Amit Rawat explains in his github repository can be leveraged here for your need.

It basically boils down to you interacting with chrome dev tools via remote debugging. Selenium4 has support for this baked into it, but the above repo can be referred for figuring out how to do it in Selenium3.

Thanks & Regards
Krishnan Mahadevan

"All the desirable things in life are either illegal, expensive, fattening or in love with someone else!"
My Scribblings @ http://wakened-cognition.blogspot.com/
My Technical Scribblings @ https://rationaleemotions.com/


On Sat, Jan 25, 2020 at 8:46 AM Geo Martinez <fixco...@gmail.com> wrote:

Screenshot (17).png

Hi , im looking for a way to get all the json response data from the Network Tab under Preview . In tried many ways and i can get only partial headers and some other stuff but not the required. Thanks in advance

--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to selenium-user...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/selenium-users/43b6ecc0-ce5e-4019-b739-d006fc3c9a47%40googlegroups.com.

David Genrich

unread,
Jan 26, 2020, 1:36:31 PM1/26/20
to Selenium Users
If you are looking to get that information programmatically, then what you want is BrowserMob Proxy.


Enjoy,
David Genrich

⇜Krishnan Mahadevan⇝

unread,
Jan 26, 2020, 10:30:44 PM1/26/20
to Selenium Users
David,

There are a few challenges with BMP as a solution.
  1. BMP now has to be additionally maintained if selenium grid is being leveraged for test execution.
  2. Daisy chaining of proxies needs to be figured and sorted out when there's a corporate proxy server involved.
  3. When working with SaaS providers such as SauceLabs or BrowserStack we again need to figure out wherein the eco system would BMP fit in (Should it be setup as a proxy server for the tunnelling application (or) should it be set as a proxy server at the browser level)
Thanks & Regards
Krishnan Mahadevan

"All the desirable things in life are either illegal, expensive, fattening or in love with someone else!"
My Scribblings @ http://wakened-cognition.blogspot.com/
My Technical Scribblings @ https://rationaleemotions.com/

--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to selenium-user...@googlegroups.com.

boo khoa

unread,
Jan 31, 2020, 7:27:30 AM1/31/20
to Selenium Users
hi bro , forgive my english so bad . 
this is code to get json TabNetWork 

doawload Json.jar or user  maven



System.setProperty("webdriver.chrome.driver", "D:\\Doawload\\testdriverVersion\\chromedriver_win32ver79.0.3945.36\\chromedriver.exe");

        options = new ChromeOptions();

 DesiredCapabilities cap = DesiredCapabilities.chrome();
 cap.setCapability(ChromeOptions.CAPABILITY, options);

LoggingPreferences logPrefs = new LoggingPreferences();
logPrefs.enable(LogType.PERFORMANCE, Level.ALL);
options.setCapability("goog:loggingPrefs", logPrefs);

        driver = new ChromeDriver(options);
        driver.get(url);

  try {
            String currentURL = driver.getCurrentUrl();
            LogEntries logs = driver.manage().logs().get("performance");
            int status = -1;
            System.out.println("\\nList of log entries:\\n");
            for (Iterator<LogEntry> it = logs.iterator(); it.hasNext();) {
                LogEntry entry = it.next();
                try {
                    JSONObject json = new JSONObject(entry.getMessage());

                    // System json messenger 
                    System.out.println(json.toString());
                    JSONObject message = json.getJSONObject("message");
                    String method = message.getString("method");

                    if (method != null && "Network.responseReceived".equals(method)) {
                        JSONObject params = message.getJSONObject("params");
                        JSONObject response = params.getJSONObject("response");
                        String messageUrl = response.getString("url");
                        if (currentURL.equals(messageUrl)) {

                            status = response.getInt("status");

                            System.out.println("---------- bingo !!!!!!!!!!!!!! returned response for " + messageUrl
                                    + ": " + status);

                            System.out.println("=======================================================");
                            System.out.println("=======================================================");
                            System.out.println("=======================================================");
                            System.out.println("---------- bingo !!!!!!!!!!!!!! headers: " + response.get("headers"));
                        }
                    }
                } catch (JSONException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
            }
            System.out.println("\nstatus code: " + status);
        } finally {

            if (driver != null) {
                System.out.println("stop ");
            }
        }

goodluck


Reply all
Reply to author
Forward
0 new messages