Selenium c# – Clearing cache and browsing data


In my test script, I am having selenium open up the chrome settings page. On that page, I want it to select the “Clear Data” button.

    driver.FindElement(By.CssSelector("* /deep/ #clearBrowsingDataConfirm"));

I get an error saying the element not found. I have tried using just with the “ID” as well. Is there another way to accomplish this.


That button is really hard to reach, because polymer.
Try this one, it works for me.

using System;
using OpenQA.Selenium;
using OpenQA.Selenium.Chrome;

namespace Selenium_test
    class Program
        static IWebDriver driver;

        static void Main(string[] args)
            driver = new ChromeDriver();
            driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(5);

            IWebElement root1 = driver.FindElement(By.CssSelector("settings-ui"));
            IWebElement shadowRoot1 = expandRootElement(root1);
            IWebElement root2 = shadowRoot1.FindElement(By.CssSelector("settings-main"));
            IWebElement shadowRoot2 = expandRootElement(root2);
            IWebElement root3 = shadowRoot2.FindElement(By.CssSelector("settings-basic-page"));
            IWebElement shadowRoot3 = expandRootElement(root3);
            IWebElement root4 = shadowRoot3.FindElement(By.CssSelector("settings-section > settings-privacy-page"));
            IWebElement shadowRoot4 = expandRootElement(root4);
            IWebElement root5 = shadowRoot4.FindElement(By.CssSelector("settings-clear-browsing-data-dialog"));
            IWebElement shadowRoot5 = expandRootElement(root5);
            IWebElement root6 = shadowRoot5.FindElement(By.CssSelector("#clearBrowsingDataDialog"));
            IWebElement root7 = root6.FindElement(By.CssSelector("cr-tabs[role='tablist']"));


            IWebElement clearDataButton = root6.FindElement(By.CssSelector("#clearBrowsingDataConfirm"));


        private static IWebElement expandRootElement(IWebElement element)
            return (IWebElement)((IJavaScriptExecutor)driver).ExecuteScript("return arguments[0].shadowRoot", element);

Answered By – Lanki

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published