plaidshirt
plaidshirt

Reputation: 5671

Clear browser cache and history with Selenium WebDriver

I use Selenium WebDriver 3.141.59 with ChromeDriver and try to remove browser cache and history during test execution. I have found several solutions about using chrome://settings/clearBrowserData page in test scripts, but these seems flaky.

In v4.0, there will be a better solution to interact with DevTools, but it isn't yet released.

driver.getDevTools().createSessionIfThereIsNotOne();
driver.getDevTools().send(Network.clearBrowserCookies());

Upvotes: 0

Views: 1495

Answers (1)

Harit Yadav
Harit Yadav

Reputation: 58

Whenever chrome opens it stores info in a profile folder. The best solution might be to create a custom profile folder every time you start the driver.

ChromeOptions chromeProfile = new ChromeOptions();
chromeProfile.addArguments("user-data-dir=" + chromeProfilePath);
WebDriver driver = new ChromeDriver(chromeProfile);

Upvotes: 1

Related Questions