How can I remove google chrome cookies

后端 未结 3 584
陌清茗
陌清茗 2020-12-07 04:37

I\'m trying to remove cookies of chrome browser. Firstly I declared the path

string chromeLocation1 = \"C:\\\\Users\\\\\" + Environment.UserName.ToString() +         


        
相关标签:
3条回答
  • 2020-12-07 05:16

    You can delete all cookies with selenium framework.

    1) Install selenium framework - Selenium WebDriver and Selenium WebDriver Support Classes (the easiest way to do this is by using NuGet)

    NuGet

    2) Use the following code to delete all cookies:

    var chromeUserData = "C:\\Users\\" + Environment.UserName.ToString(CultureInfo.InvariantCulture) + "\\AppData\\Local\\Google\\Chrome\\User Data";
    var chromeAdvancedSettings = "chrome://settings/clearBrowserData";
    var options = new ChromeOptions();
    options.AddArgument("--lang=en");
    options.AddArgument("--user-data-dir=" + chromeUserData);
    options.LeaveBrowserRunning = false;
    var driver = new ChromeDriver(options);
    driver.Navigate().GoToUrl(chromeAdvancedSettings);
    
    var frame = driver.FindElement(By.XPath("//iframe[@src='chrome://settings-frame/clearBrowserData']"));
    var frameDriver = driver.SwitchTo().Frame(frame);
    var dropDown = new SelectElement(frameDriver.FindElement(By.Id("clear-browser-data-time-period")));
    dropDown.SelectByIndex(4);
    var elm = driver.FindElement(By.Id("delete-cookies-checkbox"));
    if (!elm.Selected) elm.Click();
    elm = driver.FindElement(By.XPath("//button[@id='clear-browser-data-commit']"));
    elm.Click();
    var waiter = new WebDriverWait(driver, TimeSpan.FromSeconds(60));
    waiter.Until(wd => wd.Url.StartsWith("chrome://settings"));
    driver.Navigate().GoToUrl("chrome://newtab");
    

    [Selenium documentation]

    0 讨论(0)
  • 2020-12-07 05:16

    if You want to delete your browser all data using C# language then you can delete each browser history,cookies etc (all data) using different code.

    Here i write some code for deleting all data of Internet explorer

    1-- Delete all data/History of Internet Explorer in a button click (Window Form application or WPF application)

    private void button1_Click(object sender, EventArgs e)
            {
                //For internet explorer
                System.Diagnostics.Process.Start("rundll32.exe", "InetCpl.cpl,ClearMyTracksByProcess 255");
    
            }
    

    2--- Now the importent browser Google Chrome (the mystery because everyone try to delete all history of it using SQLite but it wrong). Dont use SQLite database because google chrome Hold all data( History, Cookies, and etc) in following location

    C:\Users\UserName(Your PC Name)\AppData\Local\Google\Chrome\User Data

    just delete all 'User Data' Folder or all the folders and files within it. then you will see your all history and cookies clear.

    Following is the code for it.

    private void button1_Click(object sender, EventArgs e)
            {
                //For internet explorer
                System.Diagnostics.Process.Start("rundll32.exe", "InetCpl.cpl,ClearMyTracksByProcess 255");
    
                // for Google Chrome.
                string rootDrive = Path.GetPathRoot(Environment.SystemDirectory); // for getting primary drive 
                string userName = Environment.UserName; // for getting user name
    
                  // first close all the extension of chrome (close all the chrome browser which are opened)
    
                try
                {
                    Process[] Path1 = Process.GetProcessesByName("chrome");
                    foreach (Process p in Path1)
                    {
                        try
                        {
                            p.Kill();
                        }
                        catch { }
                        p.WaitForExit();
                        p.Dispose();
                    }
    
    
                    System.IO.DirectoryInfo downloadedMessageInfo = new DirectoryInfo(rootDrive + "Users\\"+userName+"\\AppData\\Local\\Google\\Chrome\\User Data");
    
    
                    try
                    {
                        foreach (FileInfo file in downloadedMessageInfo.GetFiles())
                        {
                            file.Delete();
                        }
                    }
                    catch { }
    
                    try
                    {
                        foreach (DirectoryInfo dir in downloadedMessageInfo.GetDirectories())
                        {
                            dir.Delete(true);
                        }
                    }
                    catch { }
                }
                catch (IOException ex)
                {
                    MessageBox.Show(ex.Message);
                }
                    label1.Text = " History Deleted successfully.";
            }
    
    0 讨论(0)
  • 2020-12-07 05:21

    you can clear the cookies history and cache by following the below console application

    https://stackoverflow.com/a/57111667/9377382

    0 讨论(0)
提交回复
热议问题