how to click on clear button to delete the cookies and caches in firefox 61.0.1 (64-bit) with selenium.
Once I enter the url "about:preferences#privacy". I am navigated to Options page. Then clicked on "Clear data" button under cookies and site data. It got successful. Now the pop up appears stating that "Clearing all cookies and site data stored by Firefox may sign you out of websites and remove offline web content. Clearing cache data will not affect your logins." Then I need to click on Clear button which is not getting automated. Then One alert box appears. I should click on that accept button also. Please help me how to automate the clear button first...
I translated your code in Java, in case someone needs it. Tested with selenium-java 3.141.59 and Firefox 68:
importorg.openqa.selenium.By;importorg.openqa.selenium.WebDriver;importorg.openqa.selenium.firefox.FirefoxDriver;importorg.openqa.selenium.firefox.FirefoxOptions;importorg.openqa.selenium.firefox.FirefoxProfile;importorg.openqa.selenium.support.ui.ExpectedConditions;importorg.openqa.selenium.support.ui.WebDriverWait;importorg.openqa.selenium.JavascriptExecutor;publicclassFirefoxClearCache{privatefinalStringdialogSelector="#dialogOverlay-0 > groupbox:nth-child(1) > browser:nth-child(2)";privatefinalStringacceptDialogScript="const browser = document.querySelector('"+dialogSelector+"');"+"browser.contentDocument.documentElement.querySelector('#clearButton').click();";privateBygetClearSiteDataButton(){returnBy.cssSelector("#clearSiteDataButton");}privateBygetClearSiteDataDialog(){returnBy.cssSelector(dialogSelector);}privatevoidclearFirefoxCache(){driver.get("about:preferences#privacy");WebDriverWaitwait=newWebDriverWait(driver,10);// Click the "Clear Data..." button under "Cookies and Site Data".wait.until(ExpectedConditions.visibilityOfElementLocated(getClearSiteDataButton()));driver.findElement(getClearSiteDataButton()).click();// Accept the "Clear Data" dialog by clicking on the "Clear" button.wait.until(ExpectedConditions.visibilityOfElementLocated(getClearSiteDataDialog()));((JavascriptExecutor)driver).executeScript(acceptDialogScript);// Accept the confirmation alert.wait.until(ExpectedConditions.alertIsPresent());driver.switchTo().alert().accept();}}
Comments
how to click on clear button to delete the cookies and caches in firefox 61.0.1 (64-bit) with selenium.
Once I enter the url "about:preferences#privacy". I am navigated to Options page. Then clicked on "Clear data" button under cookies and site data. It got successful. Now the pop up appears stating that "Clearing all cookies and site data stored by Firefox may sign you out of websites and remove offline web content. Clearing cache data will not affect your logins." Then I need to click on Clear button which is not getting automated. Then One alert box appears. I should click on that accept button also. Please help me how to automate the clear button first...
export
Thanks for pointing this out. I updated the script and article for FF 61.
export
I translated your code in Java, in case someone needs it. Tested with selenium-java 3.141.59 and Firefox 68:
export
Thanks!
export