How to get total number of requests per second using selenium/selenide webdriver

832 views Asked by At

I want to get the total number of request on network for specific url. how can I do it using selenium or selenide. There is a search bar on my webpage and if I start typing in the search box it will show the auto complete result and on every character typed there is a request made. I want to check that how many time request is made.

Can someone please help in this regard or any hint if it is possible using selenium webdriver?

1

There are 1 answers

0
Shubham Jain On

Yes, you can do that using JavascriptExecutor.

Code is as below:

ChromeOptions options = new ChromeOptions();
options.addArguments("start-maximized");
DesiredCapabilities capabilities = DesiredCapabilities.chrome();
capabilities.setCapability(ChromeOptions.CAPABILITY, options);
WebDriver driver = new ChromeDriver(capabilities);
driver.get("http://www.google.com");
String scriptToExecute = "var performance = window.performance || window.mozPerformance || window.msPerformance || window.webkitPerformance || {}; var network = performance.getEntries() || {}; return network;";
String netData = ((JavascriptExecutor)driver).executeScript(scriptToExecute).toString();
System.out.println(netData);

The first code return network return network;" because of this JS tag. You can remove JS code of entity which you don't require.