0

How to get value of specific row in network payload with BrowserMobProxyServer? I want to get the value indicated in the screenshot, the value of "q". There is no need to write down everything to har file, I just want to get the value of "q".

I have the following code, but I don't know what to do next.

public static void main(String[] args) throws UnknownHostException, InterruptedException  {

    WebDriver             driver;
    BrowserMobProxyServer proxy;
    Proxy                 seleniumProxy;
            
    proxy = new BrowserMobProxyServer();
    proxy.start(8080);
    seleniumProxy = ClientUtil.createSeleniumProxy(proxy);
    
    String hostIp = Inet4Address.getLocalHost().getHostAddress();
    
    seleniumProxy.setHttpProxy(hostIp + ":" + proxy.getPort());
    seleniumProxy.setSslProxy(hostIp + ":" + proxy.getPort());
    proxy.setHarCaptureTypes(CaptureType.RESPONSE_CONTENT, CaptureType.REQUEST_CONTENT,
            CaptureType.RESPONSE_HEADERS, CaptureType.REQUEST_HEADERS
            );
    
    System.setProperty("webdriver.chrome.driver", "C://Users//Us//eclipse-workspace/chromedriver.exe");
    System.setProperty("webdriver.chrome.whitelistedIps", "");
    
    DesiredCapabilities seleniumCapabilities = new DesiredCapabilities();
    seleniumCapabilities.setCapability(CapabilityType.PROXY, seleniumProxy);
    seleniumCapabilities.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true);
    seleniumCapabilities.setCapability(CapabilityType.ACCEPT_INSECURE_CERTS,true);
    
    ChromeOptions options = new ChromeOptions();
    options.addArguments("--disable-web-security");
    options.addArguments("--allow-insecure-localhost");
    options.addArguments("--ignore-urlfetcher-cert-requests");
    
    driver = new ChromeDriver(seleniumCapabilities);
               
    driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
    driver.manage().window().maximize();    
            
    proxy.newHar("google.com");
    driver.get("https://www.google.com");
    Thread.sleep(2000);
    
    //click cookie consent button
    driver.findElement(By.xpath("//*[@id=\"L2AGLb\"]/div")).click();
    
    //type in "mercedes" in search bar    driver.findElement(By.xpath("/html/body/div[1]/div[3]/form/div[1]/div[1]/div[1]/div/div[2]/input"))
    .sendKeys("mercedes");
    
    //click search button driver.findElement(By.xpath("/html/body/div[1]/div[3]/form/div[1]/div[1]/div[3]/center/input[1]")).click();
    
    Thread.sleep(3000);
    
    Har har = proxy.getHar();
    
    String harFilePath = System.getProperty("C://Users//Us//eclipse-workspace//networkTestSelenium") + "testFile.har";
    File harFile = new File("C:/Users/Us/eclipse-workspace/networkTestSelenium/testFile.har");
    
    //har.writeTo(harFile);
    
    try {
        harFile.createNewFile();
        har.writeTo(harFile);
        System.out.println("attempt");
    } catch (IOException ex) {
         System.out.println (ex.toString());
         System.out.println("Could not find file " + harFilePath);
    }
    
    List<HarEntry> entries = har.getLog().getEntries();
    for (HarEntry entry : entries) {
        System.out.println("WWWWWWWWWWWWWWWWWWWWWWWWWWWWWW");
        System.out.println("Request URL: " + entry.getRequest().getUrl());
        System.out.println("Entry response status: " + entry.getResponse().getStatus());
        System.out.println("Entry response text: " + entry.getResponse().getStatusText());
        System.out.println("WWWWWWWWWWWWWWWWWWWWWWWWWWWWWW");
    }
    
    proxy.stop();
}

enter image description here

Mark Rotteveel
  • 100,966
  • 191
  • 140
  • 197
javabeginer
  • 1
  • 1
  • 6

0 Answers0