Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Timeout exception when using dev tools with selenium-java-4.0.0 and chromedriver v85

I'm trying to use selenium dev tools java API, and for multiple API methods I'm getting java.util.concurrent.TimeoutException.

For example I'm trying to use Network.clearBrowserCache, which should work accroding to chromedriver docs: https://chromedevtools.github.io/devtools-protocol/tot/Network/

I'm calling clearBrowserCache using following code: chromeDriver.getDevTools().send(Network.clearBrowserCache())

It fails, but at the same time if I use other devTools commands like this: chromeDriver.getDevTools().send(Browser.getVersion())

It returns data properly.

  • Chrome version is: 85.0.4183.39
  • Chromedriver version is: 85.0.4183.87
  • Selenium-java version is: 4.0.0-alpha-6
like image 232
XZen Avatar asked Feb 04 '23 14:02

XZen


1 Answers

Try calling createSession before calling clearBrowserCache.

Using your setup, this works:

chromeDriver.getDevTools().createSession();
chromeDriver.getDevTools().send(Network.clearBrowserCache())

and this produces java.util.concurrent.TimeoutException:

chromeDriver.getDevTools().send(Network.clearBrowserCache())

You can verify that the browser cache has been cleared with this snippet:

    ChromeDriver driver = new ChromeDriver();
    driver.get("https://refreshyourcache.com/en/cache-test/");
    Thread.sleep(2000);
    driver.getDevTools().createSession();
    driver.getDevTools().send(Network.clearBrowserCache());
    driver.get("https://refreshyourcache.com/en/cache-test/");
    Thread.sleep(5000);

If you run the code, the pages displayed in the test browser will show these images: enter image description here

If you commment out the line driver.getDevTools().send(Network.clearBrowserCache()); then you get a different result: enter image description here

like image 179
mcernak Avatar answered Feb 06 '23 11:02

mcernak