Clear cache before running some Selenium WebDriver tests using Java

Uziii picture Uziii · Oct 6, 2015 · Viewed 40.2k times · Source

I am working on Selenium WebDriver automation in java programming language. In my test suite that initiates the browser window once and perform all the tests. I want to clear the browser cache before running some tests without restarting the browser. Is there any command/function, that can achieve the purpose? Thanks.

Answer

An Khang picture An Khang · Jun 19, 2019

This is what I use in Python:

from selenium import webdriver
from selenium.webdriver.common.keys import Keys
driver = webdriver.Chrome()
driver.get('chrome://settings/clearBrowserData')
driver.find_element_by_xpath('//settings-ui').send_keys(Keys.ENTER)

You can try converting these into Java. Hope this will help! :)