I am automating web browsers to test my requirements (autofill/complete, persistence related especially). Clearing cookies is different than clearing browser history, right? Is automating to clear browser history in headless mode possible? My assumption after so much surfing online is that it's not. (I read an article that said clearing browsing history by automation in headless mode isn't allowed due to security reasons).
Also, the automated browser version which starts via selenium web drivers to test the cases doesn't store any cache as soon as it logs out of an account. Suppose I log in and log out of my account. I want selenium to keep the username I entered earlier as autofill when I refresh the page and type a few starting letters of it( which happens in normal browsers but not in the automated browser version). Can this be achieved? Thanks in advance
I've already managed to clear the browsing history of chrome in UI mode by using shadow DOM elements. This method works perfectly in user-interface mode(i.e. without headless mode) but my problem is to achieve it in a headless mode of testing( and would be great if suggested way works for other browsers too). Any suggestions or workaround for this problem?
public void clearBrowsingHistory() throws Exception {
WebDriverWait wait = new WebDriverWait(driver, 15);
driver.get("chrome://settings/clearBrowserData");
// Get shadow root elements
WebElement shadowRoot1 = expandRootElement(driver.findElement(By.xpath("/html/body/settings-ui")));
WebElement root2 = shadowRoot1.findElement(By.cssSelector("settings-main"));
WebElement shadowRoot2 = expandRootElement(root2);
WebElement root3 = shadowRoot2.findElement(By.cssSelector("settings-basic-page"));
WebElement shadowRoot3 = expandRootElement(root3);
WebElement root4 = shadowRoot3
.findElement(By.cssSelector("#advancedPage > settings-section > settings-privacy-page"));
WebElement shadowRoot4 = expandRootElement(root4);
WebElement root5 = shadowRoot4.findElement(By.cssSelector("settings-clear-browsing-data-dialog"));
WebElement shadowRoot5 = expandRootElement(root5);
WebElement root6 = shadowRoot5
.findElement(By.cssSelector("cr-dialog div[slot ='button-container'] #clearBrowsingDataConfirm"));
root6.click();
wait.until(ExpectedConditions.invisibilityOf(root6));
}